High-write sensitive query criteria (WHERE ...) in SQL Server 2k, similar to ACCESS (VB) STRCOMP functions

zhaozj2021-02-08  269

- 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

转载请注明原文地址:https://www.9cbs.com/read-1084.html

New Post(0)