I have more than one sql query(25 to be exact) and want to return the results as one row of results. for example…
–Get the Barcodes that have a EnvPrint Record in the Database
select count(distinct jtbarcode) as CountEP
from jobtracker with(nolock)
where jtprocess = 'EnvPrint' and jtbarcode in(Select lookupcode from data with(nolock) where clientid = 123 and batchid = 12345 and jobid = 1 and subjobid = 1 and entrytype<>'c' and entrytype<>'m')
GROUP BY jtBatchid
–Get the Barcodes that have a VerifyEnvPrint Record in the Database
select count(distinct jtbarcode) as CountEVP
from jobtracker with(nolock)
where jtprocess = 'Verify-EnvPrint' and jtbarcode in(Select lookupcode from data with(nolock) where clientid = 123 and batchid = 12345 and jobid = 1 and subjobid = 1 and entrytype<>'c' and entrytype<>'m')
GROUP BY jtBatchid
this produces
CountEP
18
Count EVP
18
Is it possible to return one row with those results as 2 separate columns?
I tried a Union but it made 2 rows and one column
yes. Leverage the fact that COUNT ignores NULL
This works because you have very similar WHERE clauses. It also means you only touch the table once too so should be far quicker over many result sets if they are similar