查询中跨越多行的 SQL 字符串值 [英] SQL string value spanning multiple lines in query

查看:27
本文介绍了查询中跨越多行的 SQL 字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:个人简介可能包含撇号(见更新示例)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆