Commonly use sql function Part II
String Functions Đôi khi một số hàm String rất tiện dụng. Hãy thảo luận về chúng từng cái một. ASCII() Trả về giá trị mã ASCII của ký tự ngoài cùng bên trái của biểu thức ký tự. Syntax ASCII ( character_expression ) Arguments: character_expression : Là một biểu thức của kiểu char hoặc varchar. Return Types: Int Example : SELECT ASCII( ' A' ) SET TEXTSIZE 0 SET NOCOUNT ON -- Create the variables for the current character string position -- and for the character string. DECLARE @position int , @string char ( 15 ) -- Initialize the variables. SET @position = 1 SET @string = ' The codeProject' WHILE @position <= DATALENGTH( @string ) BEGIN SELECT ASCII(SUBSTRING( @string , @position , 1 )), CHAR (ASCII(SUBSTRING( @string , @position , 1 ))) SET @position = @position + 1 END SET NOCOUNT OFF Output: -- --------- 65 -- --------- ---- 84 T -- --------- ---- 104 ...