Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 RE: 4guysfromrolla sqlguru article

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-02-22 : 09:59:24
Michaël Borgonjon writes "An answer to the question asked (URL: http://www.4guysfromrolla.com/webtech/sqlguru/q022400-1.shtml)

Write a user-defined function like this one:
------------------------------------------------------------
CREATE FUNCTION fn_string_compare (
@string1 VARCHAR(20),
@string2 VARCHAR(20)
)
RETURNS INT
AS

BEGIN
DECLARE
@ok BIT,
@index INT

IF LEN(@string1) <> LEN(@string2) BEGIN
RETURN -1
END -- IF

SET @ok = 1
SET @index = 0
WHILE @index < LEN(@string1) AND @ok = 1 BEGIN
IF ASCII(SUBSTRING(@string1, @index, 1)) <> ASCII(SUBSTRING(@string2, @index, 1)) BEGIN
SET @ok = 0
END -- IF

SET @index = @index + 1
END -- WHILE

IF @ok = 0 BEGIN
RETURN -1
END -- IF

RETURN 0
END

------------------------------------------------------------

Then, in your select statement, include a where condition

WHERE dbo.fn_string_compare([your first string value], [value to compare with])

This seems the easiest way to me...

Regards,

Michael"

izaltsman
A custom title

1139 Posts

Posted - 2002-02-22 : 10:23:24
If I need a case-sensitive comparison of strings, I usually just CAST them as binary, and then compare...

Go to Top of Page
   

- Advertisement -