查询中跨越多行的 SQL 字符串值 [英] SQL string value spanning multiple lines in query
问题描述
更新:个人简介可能包含撇号(见更新示例)
UPDATE: the bio may contain apostrophes (see updated example)
我有一个 SQL 查询,它的值跨越多行并导致查询失败:
I have an SQL query that has a value which spans multiple lines and it causes the query to fail:
UPDATE User SET UserId=12345, Name="J Doe", Location="USA", Bio="I'm a
bio that has an apostrophe, and I'm
spanning multiple lines!"
WHERE UserId=12345
在 C# 中,您可以在字符串 Bio=@"..."
之前放置一个 @
以允许它跨越多行,但我不是确定如何使用 SQL 查询实现相同的目标.如何让一个字符串跨越多行,而无需手动连接字符串之类的操作:
In C# you can put an @
before the string Bio=@"..."
in order to allow it to span multiple lines, but I'm not sure how the same thing can be achieved with SQL queries. How do you get a string to span multiple lines without having to do things like manually concatenating the strings:
Bio="I'm a"
+" bio that has an apostrophe, and I'm"
+" spanning multiple lines!"
推荐答案
SQL Server 允许以下(注意使用单引号而不是双引号)
SQL Server allows the following (be careful to use single quotes instead of double)
UPDATE User
SET UserId = 12345
, Name = 'J Doe'
, Location = 'USA'
, Bio='my bio
spans
multiple
lines!'
WHERE UserId = 12345
这篇关于查询中跨越多行的 SQL 字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!