首页 > 解决方案 > 如何将长选择语句插入或更新到列中?

问题描述

所以我有这就是我想做的

我的表名称是 GameInvLoc,包含 3 列 ID、GameLoc、GameInv

ID   GameLoc    GameInv
1    Bre        Null

我想做这个

Update GameInvLoc
   set GameInv = 'select 'ROlID,Whse,Company,LocationNo' union all select concat(id,',',Whse,',',Company,',',LocationNo) from CINT..vwGameReport' 
 where id = 1

但我在引用时遇到问题,他们去哪里我得到语法错误。

有人知道这样做的正确方法吗?

标签: sqlinsert

解决方案


您必须使用单引号两次来表示字符串文字中的一个单引号。

像这样的东西:

Update GameInvLoc
   set GameInv = 'select ''ROlID,Whse,Company,LocationNo'' union all select concat(id,'','',Whse,'','',Company,'','',LocationNo) from CINT..vwGameReport' 
 where id = 1

推荐阅读