[英]Inserting special characters into SQL Server 2008 RE
I am reading some data from a database table and the text contains the '/' character. 我正在从数据库表中读取一些数据,并且文本包含“ /”字符。
I now need to insert this string into a different SQL table but I'm having problems escaping it correctly. 现在,我需要将此字符串插入另一个SQL表中,但是在正确转义时遇到了问题。
If the string I read contains this pattern: 如果我读取的字符串包含此模式:
Test/test2
测试/测试2
After some google searching, I am using to insert the text (google refs Ref1 and Ref2 ) 谷歌搜索后,我用来插入文本(谷歌参考Ref1和Ref2 )
Field1= replace (cast('Test/th' as nvarchar),'/','\\\')
But it still returns the error: 但是它仍然返回错误:
Msg 8152, Level 16, State 2, Line 18 String or binary data would be truncated.
消息8152,级别16,状态2,行18字符串或二进制数据将被截断。
If I use: 如果我使用:
Field1= replace (cast('Test/th' as nvarchar),'/','')
Everything is fine 一切顺利
Can anyone help me with my escape clause please? 有人可以帮我逃脱条款吗?
我认为您的列字段长度设置为6。将其更改为7。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.