I have here a query that gives two rows of results:
SELECT @SlsChannelDiv= a.division,@SlsChannel= a.department
FROM dbo.m_SalesCode a left join dbo.m_SalesCode b
ON a.up1_code=b.sales_code left join vwEmployeeAds v
ON a.user_id=v.login
WHERE v.login = @SalesLogin
I would like to use the @SlsChannel
parameter for other queries.
Select * from wo where sales in (@SlsChannel)
but this always gives the first row of results.
I can modify my first query by giving an XML path:
SELECT @SlsChannelDiv= a.division,@SlsChannel= a.department
FROM dbo.m_SalesCode a left join dbo.m_SalesCode b
ON a.up1_code=b.sales_code left join vwEmployeeAds v
ON a.user_id=v.login
WHERE v.login = @SalesLogin For XML PATH ('')
However, I get an error such as: The FOR XML clause is not allowed in a ASSIGNMENT statement.
Is it possible to create a @SLSChannel
value, comma delimited, in an In
parameter?
Select * from wo where sales in (SELECT a.department
FROM dbo.m_SalesCode a left join dbo.m_SalesCode b
ON a.up1_code=b.sales_code left join vwEmployeeAds v
ON a.user_id=v.login
WHERE v.login = @SalesLogin)
How about querying it like this? :)