我想通过nvarchar值uniqueidentifier。从字符串转换为uniqueidentifier时转换失败?
例如:
Declare @test nvarchar(max);
set @test = '''' + '77494371-30c1-4d2e-8dea-58dbefb325cc' + '''' --+ ',' + '''' + 'cb4229a2-76f8-4d68-aef7-f0bae089b382' + '''';
print @test;
Select * from Table1 where ID in (@test);
我试图通过上述的条件。那个时候我面临以下错误:
'77494371-30c1-4d2e-8dea-58dbefb325cc','cb4229a2-76f8-4d68-aef7-f0bae089b382'
Msg 8169, Level 16, State 2, Line 5
Conversion failed when converting from a character string to uniqueidentifier.
如果有任何的方式来传递多UNIQUEIDENTIFIER值Where In
条件。
请帮我解决这个问题。
不能使用字符串包含可变像'“X”,“Y”,“Z” '在in子句中,并认为它会获取3个值。它会尝试找到一个值,“X”,“Y”,“Z”。您必须创建动态SQL,或者使用某种表结构,如表变量。 –