问题
Given SQL Server 2012, how can I insert control characters (the ones coded under ASCII 32, like TAB, CR, LF) in a nvarchar or varchar column from a SQL script?
回答1:
Unless I miss something in the question you can do this using TSQL CHAR() function:
INSERT INTO MyTable(ColName) VALUES(CHAR(13) + CHAR(10))
Will insert CR/LF. Same for other codes.
Edit there is TSQL NCHAR() as well for Unicode characters.
回答2:
Please note that the function may vary depending on the type of your column, using the wrong function can result in wrong encoding.
nchar/nvarchar http://technet.microsoft.com/en-us/library/ms186939.aspx
char/varchar http://technet.microsoft.com/en-us/library/ms176089.aspx
来源:https://stackoverflow.com/questions/20748811/insert-control-characters-in-nvarchar-or-varchar-from-sql-script