Link to home
Start Free TrialLog in
Avatar of KeirMcCann
KeirMcCann

asked on

Running a query within a query

I want to be able to run another query using the same fields but to find all places where U_IIS_EXT text is not null and then output the data underneath the current set of data. There would be no data in T0.U_IIS_DDATE or SLPNAME but it would fill data in U_IIS_INADR , T0.Dscription and U_IIS_EXT
SELECT  T2.U_IIS_INADR, T0.[Dscription], T0.U_iis_ddate, T1.[SlpName], T0.U_IIS_EXT as Work_Requiring_attention FROM DLN1 T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN ODLN T2 ON T0.DocEntry = T2.DocEntry left outer join OSCN T3 on t3.ItemCode = t0.ItemCode and t3.Cardcode = SUBSTRING(t2.CardCode, 1, 8) WHERE T2.[U_IIS_JTYPE] = '6' and T0.[U_iis_ddate] = '[%0]' and T2.[CardName] = '[%1]'

Open in new window

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

I think you want either a UNION query?
could you show the query for the data that you want to have "below"?
Avatar of KeirMcCann
KeirMcCann

ASKER

SELECT  T2.U_IIS_INADR, T0.[Dscription, T0.U_IIS_EXT as Work_Requiring_attention where T0.U_IIS_EXT is not Null
so, a UNION:
SELECT  T2.U_IIS_INADR, T0.[Dscription], T0.U_iis_ddate, T1.[SlpName], T0.U_IIS_EXT as Work_Requiring_attention FROM DLN1 T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN ODLN T2 ON T0.DocEntry = T2.DocEntry left outer join OSCN T3 on t3.ItemCode = t0.ItemCode and t3.Cardcode = SUBSTRING(t2.CardCode, 1, 8) WHERE T2.[U_IIS_JTYPE] = '6' and T0.[U_iis_ddate] = '[%0]' and T2.[CardName] = '[%1]'
 
UNION ALL
 
SELECT  T2.U_IIS_INADR, T0.[Dscription], null, null, T0.U_IIS_EXT as Work_Requiring_attention where T0.U_IIS_EXT is not Null

Open in new window


Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "T0.U_IIS_EXT" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "T2.U_IIS_INADR" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "T0.Dscription" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "T0.U_IIS_EXT" could not be bound.

Thanks for your time angel
your query had no FROM, I overlooked that ..
SELECT  T2.U_IIS_INADR, T0.[Dscription], T0.U_iis_ddate, T1.[SlpName], T0.U_IIS_EXT as Work_Requiring_attention FROM DLN1 T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN ODLN T2 ON T0.DocEntry = T2.DocEntry left outer join OSCN T3 on t3.ItemCode = t0.ItemCode and t3.Cardcode = SUBSTRING(t2.CardCode, 1, 8) WHERE T2.[U_IIS_JTYPE] = '6' and T0.[U_iis_ddate] = '[%0]' and T2.[CardName] = '[%1]'
 
UNION ALL
 
SELECT  T2.U_IIS_INADR, T0.[Dscription], null, null, T0.U_IIS_EXT as Work_Requiring_attention 
FROM DLN1 T0  INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN ODLN T2 ON T0.DocEntry = T2.DocEntry left outer join OSCN T3 on t3.ItemCode = t0.ItemCode and t3.Cardcode = SUBSTRING(t2.CardCode, 1, 8) WHERE T2.[U_IIS_JTYPE] = '6' and T0.[U_iis_ddate] = '[%0]' and T2.[CardName] = '[%1]'
AND T0.U_IIS_EXT is not Null

Open in new window

thanks again, it isnt bringing up an error but nor it isnt pulling anything up for U_IIS_EXT either

Any chance you know why?  I have one field with the text "Test" in it but it doesnt pull this data up
untitled2.JPG
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial