March 30, 2015 at 11:32 am
SELECT LEFT(InstanceName,CHARINDEX(' \ ',InstanceName)-1)
FROM ServerDB
Returns the following error.
Invalid length parameter passed to the SUBSTRING function.
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
March 30, 2015 at 11:54 am
That happens when the backslash doesn't exist in the string and generates 0-1=-1 which is invalid for the parameter.
Use a safety net to prevent this and remove the spaces (unless you need them).
SELECT LEFT(InstanceName,CHARINDEX('\',InstanceName+'\')-1)
FROM ServerDB
March 30, 2015 at 11:56 am
Luis Cazares (3/30/2015)
That happens when the backslash doesn't exist in the string and generates 0-1=-1 which is invalid for the parameter.Use a safety net to prevent this and remove the spaces (unless you need them).
SELECT LEFT(InstanceName,CHARINDEX('\',InstanceName+'\')-1)
FROM ServerDB
Sweet. Thanks!
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply