简体   繁体   English

无法绑定多部分标识符(SQL SERVER)

[英]Multi-part identifier could not be bound (SQL SERVER)

I am programming in Lua programming language and using SQL along with it. 我正在使用Lua编程语言进行编程,并与之一起使用SQL。

In my program , I have a select statement that is fetching userid from from a table named "users" and storing it in a variable called "U". 在我的程序中,我有一条select语句,该语句从名为“ users”的表中获取userid并将其存储在名为“ U”的变量中。

This is the statement : 这是声明:

local U = conn:query{live=true,sql="select top 1 userid from users where username = 'iguana01'"}

Now, since the top 1 userid is stored in U , I want that to us in my next statement which is 现在,由于前1个用户ID存储在U中,因此我希望在我的下一条语句中将它提供给我们

"UPDATE dbo.Messages SET Status='R' , ModifyDate = GetUTCDate(), ModifiedById = U.userid WHERE MessageId ='10'"

but if I am using U.userid, It says "Multipart identifier could not be bound".Secondly, this error is there because I am trying to use U.userId which is data from users table in the ModifiesById field of Messages table but I do not have any common column between these tables to make a join. 但是,如果我使用的是U.userid,它会显示“无法绑定多部分标识符”。其次,出现此错误是因为我试图使用U.userId,它是Messages表的ModifiedById字段中的users表中的数据,但我这些表之间没有任何公共列可以进行联接。 My only requirement is to use top 1 value of UserId column of Users table in ModifiedById column of Message Table . 我唯一的要求是在Message Table的ModifiedById列中使用Users表的UserId列的前1个值。 How can I fix this ? 我怎样才能解决这个问题 ?

I believe the error is there because U.userid is not known to SQL query engine: U is a local variable, which the engine does not have access to. 我相信错误是存在的,因为SQL查询引擎不知道U.userid:U是本地变量,引擎无法访问。 Try changing the second query to concatenate the value of U.userid into the string: 尝试更改第二个查询以将U.userid的值连接到字符串中:

"UPDATE dbo.Messages SET Status='R' , ModifyDate = GetUTCDate(), ModifiedById = " .. U.userid .. " WHERE MessageId ='10'"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM