日期:2014-05-18 浏览次数:20416 次
SELECT EM007 FROM [EAPS].[dbo].APSEMP WHERE EM001 = 'hs'
'加工中心1','加工中心2','加工中心3'
SELECT [JO002] ,[JO003] FROM [EAPS].[dbo].[APSJOB] where JO015 IN ('加工中心1','加工中心2','加工中心3')
SELECT [JO002] ,[JO003] FROM [EAPS].[dbo].[APSJOB] where JO015 IN (SELECT EM007 FROM [EAPS].[dbo].APSEMP WHERE EM001 = 'hs')
declare @sql nvarchar(4000) set @sql = 'SELECT [JO002] ,[JO003] FROM [EAPS].[dbo].[APSJOB] where JO015 IN ('+SELECT EM007 FROM [EAPS].[dbo].APSEMP WHERE EM001 = 'hs'+')' exec(@sql)
------解决方案--------------------
DECLARE @STR VARCHAR(200) SET @STR='' EXEC(' SELECT @STR=EM007 FROM [EAPS].[dbo].APSEMP WHERE EM001 = ''''hs''''' SELECT [JO002] ,[JO003] FROM [EAPS].[dbo].[APSJOB] where JO015 IN ('+@STR+')'
------解决方案--------------------
SELECT [JO002], [JO003] FROM [EAPS].[dbo].[APSJOB] TA WHERE EXISTS ( SELECT 1 FROM [EAPS].[dbo].APSEMP TB WHERE TB.EM001 = 'hs' AND TA.J0015 = TB.EM007 )
------解决方案--------------------
DECLARE @STR VARCHAR(200) SET @STR='' SELECT @STR=EM007 FROM [EAPS].[dbo].APSEMP WHERE EM001 = 'hs' EXEC(' SELECT [JO002] ,[JO003] FROM [EAPS].[dbo].[APSJOB] where JO015 IN ('+@STR+')'