我需要做这个查询:
declare @no as varchar(100)
set @no='11,2,23'
select * from ft (nolock) where fno in (@no)
但一直有这个错误:Error convert data type varchar to numeric
fno 是表中的数字
我需要做这个查询:
declare @no as varchar(100)
set @no='11,2,23'
select * from ft (nolock) where fno in (@no)
但一直有这个错误:Error convert data type varchar to numeric
fno 是表中的数字
您不能直接选择数据,in (@no)
因为LIKE
需要将数据作为表格。请试试:
declare @no nvarchar(max)
set @no='11,2,23'
select * from ft (nolock) where fno in (
SELECT
Split.a.value('.', 'VARCHAR(100)') AS CVS
FROM
(
SELECT
CAST ('<M>' + REPLACE(@no, ',', '</M><M>') + '</M>' AS XML) AS CVS
) AS A CROSS APPLY CVS.nodes ('/M') AS Split(a))
您可以使用表变量轻松完成您尝试创建的查询,而不仅仅是 varchar 变量:
declare @t table (
n int
)
insert into @t
values
(1)
,(2)
,(3)
select
*
from someTable
where n in (
select
n
from @t
)