考虑下表:
DECLARE @tmp_Example
TABLE (
TestInt int,
TestName varchar(max)
);
INSERT INTO @tmp_Example (TestInt, TestName)
VALUES (22,'Bob'),
(23,'James'),
(24,'Joe');
SELECT * from @tmp_Example
WHERE TestInt = 23;
我遇到了有人可能想要为 TestInt 选择多个结果的情况,我收到的结果是这样的:
('23,24')
在不改变表的架构的情况下,如何支持这样的查询?我摆弄着像这样拆分它:
DECLARE @testEx as varchar(max) = '23,24';
SELECT * from @tmp_Example
WHERE TestInt = CAST(dbo.Split(@testEx,',') AS int);