获取sql语法错误 [英] Getting sql syntax error

查看:107
本文介绍了获取sql语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Declare @ColId uniqueidentifier

set @ColId = '1B233EE7-1668-4D03-995F-2D763BF03F06'

EXEC('update custom.location
    set siteid =' + @ColId +
    'where siteid is null')







执行上面的sql查询时得到以下错误 -

'B233EE7'附近的语法不正确。



任何人都可以提供帮助吗?




when execute above sql query get below error-
Incorrect syntax near 'B233EE7'.

Any one can help?

推荐答案

对于你正在做的事情,将@ColID声明为varchar是否有意义?



如果n ot,你可能希望把它变成一个。



此外,你不仅仅是为了构建查询的原因:

For what you're doing, wouldn't it make sense to declare @ColID a varchar?

If not, you may wish to cast it to one.

Also, any reason you don't just build the query simply as:
update custom.location set siteid=@ColId where siteid is null


如果这是微软SQL服务器,它应该是custom..location或custom.dbo.location。语法是database.owner.tablename ....否则将值定义为varchar的第一个解决方案将起作用
If this is microsoft SQL server it should be custom..location or custom.dbo.location. Syntax is database.owner.tablename....otherwise the first solution of defining the value as a varchar will work


这篇关于获取sql语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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