Get the App
SLTechnology News&Howtos  ›  Database  › 

SqlServer gets the sql statement of lowercase letters in a string

Shulou Source: shulou.com Published: 2022-06-01 03:43:45 10月22日 Update

Sometimes we will intercept some special things in the string, such as uppercase and lowercase letters, module numbers, Chinese characters, numbers, and so on. Today, we will introduce a way to get lowercase letters (also uppercase letters) in a string.

DECLARE @ s VARCHAR (MAX) = 'AbcdEf Ool'-string to be intercepted DECLARE @ temp VARCHAR (MAX) =''- temporary variable SELECT @ temp=@temp+SUBSTRING (ch, sv.number, 1) FROM (SELECT @ s AS ch) t CROSS APPLY [master] .dbo.spt _ values AS sv WHERE sv.type = 'P'AND sv.number BETWEEN 1 AND LEN (ch) AND ASCII (SUBSTRING (ch, sv.number) 1) BETWEEN ASCII ('a') AND ASCII ('z') SELECT @ temp

The results are as follows:

So we get lowercase letters, and of course we can get uppercase letters:

SELECT @ temp=@temp+SUBSTRING (ch, sv.number, 1) FROM (SELECT @ s AS ch) t CROSS APPLY [master] .dbo.spt _ values AS sv WHERE sv.type ='P' AND sv.number BETWEEN 1 AND LEN (ch) AND ASCII (SUBSTRING (ch, sv.number, 1) BETWEEN ASCII ('A') AND ASCII ('Z') SELECT @ temp

The results are as follows:

Flexible grasp, according to the needs of the application.

Summary

The above is the realization sentence of SqlServer to get the lowercase letters of the string introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

Tags: Letters characters strings small and medium uppercase uppercase letters results statements special things writing variables case lowercase numbers ways sometimes questions websites requirements Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Apple macOS vpn