none
In SP global variable issue RRS feed

  • Question

  • Could you please tell me how  to declare and use  global variable in  select sub query in Store procedure

    In  sp for some variables i need to use that in subquery.

    Here in below @Status var not accessible inside select query-

    Example-

    DECLARE @Status nvarchar(2000)

    SET @Status=('''A1'',''A2''')

    SELECT  * INTO #Temp
    FROM
    (

    SELECT *
    FROM Table1 AP
    INNER JOIN    Tabl2 EU ON AP.AId = EU.ID
    WHERE AP.Status IN (@Status) 

    )
    tbl
    Wednesday, August 9, 2017 12:08 PM

Answers

All replies

  • Hi,

    Could you please tell me how  to declare and use  global variable in  select sub query in Store procedure

    In  sp for some variables i need to use that in subquery.

    Here in below @Status var not accessible inside select query-

    Example-

    DECLARE @Status nvarchar(2000)

    SET @Status=('''A1'',''A2''')

    SELECT  * INTO #Temp
    FROM
    (

    SELECT *
    FROM Table1 AP
    INNER JOIN    Tabl2 EU ON AP.AId = EU.ID
    WHERE AP.Status IN (@Status) 

    )
    tbl

    Wednesday, August 9, 2017 12:07 PM
  • Hello,

    The 'Academic Initiatives - Technical Queries' forum is for posts Related to technical / coding / programming related issues as related to Microsoft's Academic Initiatives.

    As it's off-topic here, I am moving the question to the Where is the forum for... forum.

    Karl

    Thursday, September 7, 2017 1:54 PM
    Moderator
  • I'd ask for help over here.

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Thursday, September 7, 2017 3:36 PM
    Moderator