Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 short UNION ALL qsn

Author  Topic 

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2014-06-27 : 08:49:43
Hi just want to know can you have unlimited UNION ALL's - can i add another group of SELECT to the end of this? how many times?

SELECT
count(*)as Picking,
0 AS LaserENG
FROM

CCDTA.OEORH48,CCDTA.TRNSTAT2,CCDTA.OETRA99
WHERE OHCOM# = TSCOM# AND OHORD# = TSORD#
AND (otCOM# = OHCOM# AND OTORD#= OHORD# AND ottrnc = 'AQC')
AND OHORDT IN('RTR','INT','SAM') AND TSSTAT IN('ECT','STP')
AND OHREQD = replace(char(current date, iso), '-', '') AND
OHHLDC = ' 'AND OHORD# in(SELECT a.TSORD# FROM ASTCCDTA.TRNSTAT2 a
WHERE a.tsstat IN('AEP','BGE','EAS','REL','STP'))

UNION ALL

SELECT
0,
count(*) FROM
CCDTA.OEORH48,CCDTA.TRNSTAT2,CCDTA.OETRA99
WHERE OHCOM# = TSCOM# AND OHORD# = TSORD#
AND (otCOM# = OHCOM# AND OTORD#= OHORD# AND ottrnc = 'AQC')
AND TSSTAT IN('EAS','REL','SCC')
AND OHORDT IN('RTR','INT','SAM')
AND OHREQD = replace(char(current date, iso), '-', '') AND OHHLDC = ' '

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-06-27 : 08:52:32
You can have as many UNION ALL as you want. It is limited only by the maximum length of a query.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-06-27 : 09:21:24
I think you may hit the stack size limit with about 1300-1500 SELECTs.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

sardam98
Starting Member

10 Posts

Posted - 2014-06-29 : 03:42:56
nice



http://www.soran.edu.iq

http://www.soran.edu.iq
Go to Top of Page
   

- Advertisement -