Substring Length Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#... get some results to work with... | |
$sqlcmdParams = @{ | |
ServerInstance = 'localhost\SQLSERVER2K16' | |
Database = 'master' | |
Query = @' | |
SELECT TOP(10) | |
name | |
FROM dbo.spt_values | |
WHERE name IS NOT NULL | |
AND LEN(name) != 0 | |
ORDER BY name; | |
'@ | |
}; | |
$dbResults = Invoke-Sqlcmd @sqlcmdParams; | |
#...now check the substring function... | |
foreach ($row in ($dbResults.name)) { | |
[PSCustomObject]@{ | |
RowName = $row | |
RowSubString = $row.Substring(5, 100) | |
}; | |
}; | |
<# | |
# Error message: | |
# Exception calling "Substring" with "2" argument(s): "startIndex cannot be larger than length of string" | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment