如题,现有存储过程 sp_a 参数@ids执行的时候需要输入"ae6810f5-c1f4-4f0e-a772-bf9a6ff8fd65,1699367c-2c5a-409e-b123-eb5d00be8d81" 2个参数。 单个的可以进行转化。 多个的情况下怎么办呢? 参数@ids 已经定义为 varchar(8000)但是 where id in (@ids) 后 只有第一条数据。 好郁闷。 谢谢了。
调试欢乐多
declare @var varchar(100)
set @var='D6B183B5-CE92-4EAE-B13C-17F20B864C1F,606AF7DC-EBAD-48A0-B81C-AB8C9862E45C'
with cte as
(
select 'D6B183B5-CE92-4EAE-B13C-17F20B864C1F' as VGUID union all
select '606AF7DC-EBAD-48A0-B81C-AB8C9862E45C' union all
select '9E0DE149-D12D-4956-935C-A58528AC488D'
)
select * from cte where @var like '%'+VGUID+'%' --VGUID
--------------------------------------
--D6B183B5-CE92-4EAE-B13C-17F20B864C1F
--606AF7DC-EBAD-48A0-B81C-AB8C9862E45C--(2 row(s) affected)
id uniqueidentifier,
name varchar(10)
)
goinsert into tb select 'ae6810f5-c1f4-4f0e-a772-bf9a6ff8fd65','a'
union all select '1699367c-2c5a-409e-b123-eb5d00be8d81','b'
union all select newid(),'c'
gocreate proc sp_a @ids varchar(8000)
as
begin
select * from tb where charindex(cast(id as varchar(40)),@ids)>0
end
goexec sp_a 'ae6810f5-c1f4-4f0e-a772-bf9a6ff8fd65,1699367c-2c5a-409e-b123-eb5d00be8d81'
/**
id name
------------------------------------ ----------
AE6810F5-C1F4-4F0E-A772-BF9A6FF8FD65 a
1699367C-2C5A-409E-B123-EB5D00BE8D81 b(2 行受影响)
**/--drop table tb
--drop proc sp_a
if OBJECT_ID('test') is not null
drop table test
go
create table test(
id uniqueidentifier,
value int
)
go
insert test
select newid(),1 union all
select newid(),2 union all
select newid(),3 union all
select newid(),4 union all
select newid(),5 union all
select newid(),6
goselect * from test
where cast(id as varchar(50))
in('8A7C1009-9F97-4091-A0D1-28AA3D4ECCCB','E9A35845-99E0-4899-ACE2-213064117893')
/*
id value
--------------------------------------------------
E9A35845-99E0-4899-ACE2-213064117893 2
8A7C1009-9F97-4091-A0D1-28AA3D4ECCCB 4
*/--直接转换就好了