我这里有一个查询,它提供两行结果:
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
我想将@SlsChannel
参数用于其他查询。
Select * from wo where sales in (@SlsChannel)
但这总是给出第一行结果。
我可以通过提供XML路径来修改我的第一个查询:
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 ('')
但是,我收到错误消息,例如:The FOR XML clause is not allowed in a ASSIGNMENT statement.
是否可以在@SLSChannel
参数中创建逗号分隔的In
值?
答案 0 :(得分:1)
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)
如此查询呢? :)