Is there any way to compare two strings in SQL Server 2008 stored procedure like below?
int returnval = STRCMP(str1, str2)
Above method I find in the MySQL but not in SQL Server.
There is no built-in string compare function in SQL Server, you have to do it manually:
CASE
WHEN str1 = str2 THEN 0
WHEN str1 < str2 THEN -1
WHEN str1 > str2 THEN 1
ELSE NULL -- one of the strings is NULL so won't compare
END
Notes:
CREATE FUNCTION
etc.str1
and str2
will be column names or @variables