Create PROCEDURE [dbo].[Report_SO_SeatCont_ForVertical]
-- Add the parameters for the stored procedure here
@Vertical nvarchar(max),
@ProductLine nvarchar(max)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;    -- Insert statements for procedure here
Select P.*
from dbo._Store_VW_Product_PLP AS P
where 1=1
AND P.Vertical in (@Vertical)
AND P.ProductLine in (@ProductLine)@Vertical和@ProductLine都需要多个值,该怎么办?请高手帮忙,谢谢!

解决方案 »

  1.   

    create PROCEDURE [dbo].[Report_SO_SeatCont_ForVertical]
    -- Add the parameters for the stored procedure here
    @Vertical nvarchar(max),
    @ProductLine nvarchar(max)
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.-- Insert statements for procedure here
    declare @str varchar(1000)
    set @str='Select P.* from dbo.tb AS P where  1=1  AND P.id in ('+@Vertical+')AND P.MYstr in ('+@ProductLine+')'exec (@str)
    end
      

  2.   

    用下面的代码,@Vertical nvarchar(max),@ProductLine nvarchar(max)可能要改一下,不能取max
    Create PROCEDURE [dbo].[Report_SO_SeatCont_ForVertical]
    -- Add the parameters for the stored procedure here
    @Vertical nvarchar(max),
    @ProductLine nvarchar(max)
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;exec ('Select P.* from dbo._Store_VW_Product_PLP AS P where P.Vertical in ('+@Vertical+')
    AND P.ProductLine in ('+@ProductLine+')')
      

  3.   

    用动态sql,注意下参数格式应该就可以了
      

  4.   


    Create PROCEDURE [dbo].[Report_SO_SeatCont_ForVertical]
    -- Add the parameters for the stored procedure here
    @Vertical nvarchar(max),--其中每个值为varchar,char等类型
    @ProductLine nvarchar(max)--其中每个值为类似int类型
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;DECLARE @Vertical_TEMP NVARCHAR(MAX)
    SET @Vertical_TEMP=''''+REPLACE(@Vertical,',',''',''')+''''exec ('Select P.* from dbo._Store_VW_Product_PLP AS P where P.Vertical in ('+@Vertical_TEMP+')
    AND P.ProductLine in ('+@ProductLine+')')ENDEXEC [dbo].[Report_SO_SeatCont_ForVertical] 'A,B,C,D','1,2,3,4'
      

  5.   

    CREATE PROCEDURE [dbo].[Report_SO_SeatCont_ForVertical]
    -- Add the parameters for the stored procedure here
    @Vertical NVARCHAR(MAX),
    @ProductLine NVARCHAR(MAX)
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    -- Insert statements for procedure here
    EXEC('
    SELECT P.* 
    FROM dbo._Store_VW_Product_PLP AS P
    WHERE 1 = 1
    AND P.Vertical IN ('+@Vertical+')
    AND P.ProductLine IN ('+@ProductLine+')
    ')
    GO要注意过滤关键字,防止SQL注入攻击。请情参考精华贴之SQL注入专题。