A que no puedes pasar parametros en el in de esa manera deberias de hacer una funcion algo como esto:
Código SQL:
Ver original/****** Object: UserDefinedFunction [dbo].[SplitApplication] Script Date: 10/19/2010 15:12:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[SplitApplication](@applicationid VARCHAR(2000))
RETURNS @RtnValue TABLE
(
Id INT IDENTITY(1,1),
DATA nvarchar(100)
)
AS
BEGIN
DECLARE @Cnt INT, @SplitOn nvarchar(5)
SET @SplitOn = ','
SET @Cnt = 1
While (Charindex(@SplitOn,@applicationid)>0)
BEGIN
INSERT INTO @RtnValue (DATA)
SELECT
DATA = ltrim(rtrim(SUBSTRING(@applicationid,1,Charindex(@SplitOn,@applicationid)-1)))
SET @applicationid = SUBSTRING(@applicationid,Charindex(@SplitOn,@applicationid)+1,len(@applicationid))
SET @Cnt = @Cnt + 1
END
INSERT INTO @RtnValue (DATA)
SELECT DATA = ltrim(rtrim(@applicationid))
RETURN
END
GO
how TO USE :
SELECT * FROM TABLE WHERE DATA IN (
SELECT * FROM SplitApplication('1,1,1,1')
)
saludos!