Implement case-sensitive query conditions (WHERE…) in SQL Server 2 K ...), StrComp functions similar to Access (VB)

Source: Internet
Author: User
Tags rtrim

-- Create the following User-Defined Function (UDF)

Create function StrComp (@ Str1 VARCHAR (50), @ Str2 VARCHAR (50 ))
-- Alter function StrComp (@ Str1 VARCHAR (50), @ Str2 VARCHAR (50 ))
RETURNS INTEGER
AS
BEGIN
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 )))
If len (LTRIM (RTRIM (@ Str1) <LEN (LTRIM (RTRIM (@ Str2) -- THEN
SET @ iLen = LEN (LTRIM (RTRIM (@ Str2 )))
WHILE (@ I <@ iLen)
BEGIN
IF (ASCII (SUBSTRING (@ Str1, @ I + 1, 1) = ASCII (SUBSTRING (@ Str2, @ I + 1, 1) -- THEN
SET @ I = @ I + 1
ELSE
BEGIN
SET @ y = 0
BREAK
END
END
RETURN @ y
END

Test:
Select *
From Table1
Where dbo. StrComp (Field1, 'aabb ') = 1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.