SQL - using a variable for an IN clause

后端 未结 7 1395
醉话见心
醉话见心 2021-01-21 09:50

I wish to do something like the following:

declare @FrameNumber nvarchar(20)
set @FrameNumber = \'(p1, p2)\'

select from myTable where c1 in @FrameNumber
         


        
7条回答
  •  感情败类
    2021-01-21 09:53

    DECLARE @FrameNumbers TABLE (code NVARCHAR(20) PRIMARY KEY)
    
    INSERT
    INTO   @framenumbers
    VALUES ('p1')
    
    INSERT
    INTO   @framenumbers
    VALUES ('p2')
    
    SELECT  *
    FROM    mytable
    WHERE   c1 IN
            (
            SELECT  code
            FROM    @framenumbers
            )
    

提交回复
热议问题