- Create a user-defined function (UDF)
CREATE FUNCTION StrComp (@ Str1 VARCHAR (50), @ Str2 VARCHAR (50)) - ALTER FUNCTION StrComp (@ Str1 VARCHAR (50), @ Str2 VARCHAR (50)) RETURNS INTEGERASBEGIN DECLARE @i INTEGER --DECLARE @ Str1 VARCHAR (50) - Declare @ str2 varchar (50) declare @Y INT --SET @ str1 = 'a' --set @ Str2 = 'a' set @ i = 0 --select ASCII (Substring (@ str1, @ i 1, 1)) SET @ y = 1 declare @ilen int set @ilen = LEN (Ltrim (RTRIM (@ str1)))
Test: Select * from table1where dbo.strcomp (field1, 'aabb') = 1