|
I have been up and down my SQL and can't find WHY I keep getting an error on my UNION keyword. When I run the below SQL through Query Analyzer, it comes back with: Server: Msg 156, Level 15, State 1, Line 5 Incorrect syntax near the keyword 'UNION'. Server: Msg 156, Level 15, State 1, Line 8 Incorrect syntax near the keyword 'WHERE'. Server: Msg 156, Level 15, State 1, Line 14 Incorrect syntax near the keyword 'WHERE'. Any help would be appreciated. Thanks -Allen May
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
SELECT b.addition + ' ' + ISNULL(z.desc_, b.desadd) strucode, CASE b.yearblt WHEN '0' THEN ' ' ELSE STR(b.yearblt,4,0) END yearblt, CASE SUM(b.yearblt) WHEN '0' THEN ' ' ELSE STR(SUM(b.sqft))+' '+'Square Feet' END sqft, 'Addition' rec_type FROM aditions b LEFT OUTER JOIN codedesc z ON (z.GROUP_ = 'ADITIONS' AND z.code = b.addition) WHERE (b.parcelid='6010001007000' AND b.cardnum= '01') AND (b.deleted!='T' AND b.deleted!='1' OR b.deleted IS NULL)GROUP BY b.fig_id ORDER BY rec_type, strucode UNION ALL SELECT d.buildtype + ' ' + ISNULL (x.desc_, d.desout) strucode, RTRIM(d.condition) condcode, ISNULL(w.desc_,' ') conddesc, CASE d.yearblt WHERE '0' THEN ' ' ELSE STR(d.yearblt,4,0) END yearblt, CASE SUM(d.sqft) WHERE '0' THEN ' ' ELSE STR(SUM(d.sqft))+' '+'Square Feet' END sqft, 'Outbuilding' rec_type FROM outbldg d LEFT OUTER JOIN codedesc x ON (x.GROUP_ = 'OUTBLDG' AND x.code = d.buildtype) LEFT OUTER JOIN codedesc w ON (w.group_ = 'CONDITION' AND w.code = d.condition) WHERE (d.parcelid='6010001007000' AND d.cardnum='01') AND (d.deleted!='T' AND d.deleted!='1' OR d.deleted IS NULL)GROUP BY d.fig_id UNION ALL SELECT c.featrule+' '+ISNULL(c.desc_,' ') strucode, ' ' condcode, ' ' conddesc, ' ' yearblt, CASE SUM(c.units) WHERE '0' THEN ' ' ELSE STR(SUM(c.units))+' '+c.unit_type END sqft, '' rec_type FROM feature c WHERE (c.parcelid='6010001007000' AND c.cardnum= '01') AND (c.deleted!='T' AND c.deleted!='1' OR c.deleted IS NULL)GROUP BY c.featrule
|