MS SQL SERVER char 函数显示ASCII的效果

DECLARE @I INT
DECLARE @SQL NVARCHAR(max)
DECLARE @EXECSQL NVARCHAR(200)
DECLARE @RESULT NVARCHAR(MAX)
SET @I= 0
SET @SQL = 'SELECT ' 

WHILE @I<256
BEGIN
    SET @EXECSQL = 'SELECT ''TXT1'' + CHAR(' + CAST(@I AS NVARCHAR(3)) + ') + ''TXT2'' AS CHAR' +CAST(@I AS NVARCHAR(3))
    PRINT @EXECSQL
    EXEC SP_EXECUTESQL @EXECSQL

    SET @SQL = @SQL + '''TXT1'' + CHAR(' + CAST(@I AS NVARCHAR(3)) + ') + ''TXT2'' AS CHAR' +CAST(@I AS NVARCHAR(3)) + ','
    SET @I=@I+1
END
PRINT LEFT(@SQL,LEN(@SQL)-1)
SET @RESULT = LEFT(@SQL,LEN(@SQL)-1)
EXEC SP_EXECUTESQL @RESULT

MS SQL SERVER char 函数显示ASCII的效果_第1张图片

你可能感兴趣的:(SQL-SERVER)