SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Columns ins SQL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jblobner
Starting Member

USA
3 Posts

Posted - 06/24/2009 :  14:17:08  Show Profile  Reply with Quote
I have a query that returns two data sets.
select count (*) from pfvcfnh where vcfabr = 'AUDIT' and vcsta1 = 'A' and vcshdt > 20090101 and vcshdt < 20090617 union
select count (*) from pfvcfnh where vcfabr = 'AUDIT' and vcsta1 = '01' and vcshdt > 20090101 and vcshdt < 20090617;

The result looks like this.

00001
9479
19254

00001 is the column heading
9479 & 19245 are data.

How can I rewrite the query so the output is in 2 columns?

Example
00001 00002
9478 19254

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 06/24/2009 :  14:22:18  Show Profile  Reply with Quote


SELECT [00001] = SUM(CASE WHEN vcsta1 = 'A'                           
                          THEN 1 ELSE 0 
                      END)
,[00002] = SUM(CASE WHEN  and vcsta1 = '01'              
                    THEN 1 ELSE 0 END)
FROM pfvcfnh 

WHERE
vcfabr = 'AUDIT' 
 and vcshdt > 20090101 and vcshdt < 20090617




Jim
Go to Top of Page

jblobner
Starting Member

USA
3 Posts

Posted - 06/24/2009 :  14:38:11  Show Profile  Reply with Quote
Thanks for the speedy reply. I ran the query, but it returned and error

14:36:23 [SELECT - 0 row(s), 0.125 secs] [Error Code: -104, SQL State: 42601] [SQL0104] Token [ was not valid. Valid tokens: ( + * - ? : DAY RRN CASE CAST CHAR DATE DAYS HASH HOUR LEFT RANK.
... 1 statement(s) executed, 0 row(s) affected, execution time 0.125 sec

Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 06/24/2009 :  14:55:13  Show Profile  Reply with Quote
Are you querying a MS SQL Server database?

Jim
Go to Top of Page

jblobner
Starting Member

USA
3 Posts

Posted - 06/24/2009 :  17:29:49  Show Profile  Reply with Quote
No it's an AS400 database.
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17642 Posts

Posted - 06/25/2009 :  00:04:34  Show Profile  Reply with Quote
try dbforums.com. This is a MS SQL Server forum.


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000