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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Multiple Selects in one statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

phate06
Starting Member

16 Posts

Posted - 09/04/2013 :  05:49:44  Show Profile  Reply with Quote
Hi Guys

I need to return three individual results based on one table, below is my query but it does not like it, I am getting syntax errors see below too - can any one advise?

select
(
Select (COUNT (CustomerID)) as 'Trade Account' from customer where CustomerCode like 'TRC%' and Deleted = 0
Select (COUNT (CustomerID)) as 'Credit Account'from Customer where CustomerCode not like 'TRC%' and Deleted=0 and CashAccount=0
Select (COUNT (CustomerID)) as 'Cash Account' from Customer where CustomerCode like 'CAS%' and Deleted=0 and CashAccount=1
)From Customer

Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'Select'.
Msg 102, Level 15, State 1, Line 6
Incorrect syntax near ')'.

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 09/04/2013 :  06:01:15  Show Profile  Reply with Quote
--May be this you want?
Select
	(COUNT (CASE WHEN CustomerCode like 'TRC%' and Deleted = 0 THEN CustomerID END)) as 'Trade Account' ,
	(COUNT (CASE WHEN CustomerCode not like 'TRC%' and Deleted=0 and CashAccount=0 THEN CustomerID END )) as 'Credit Account',
	(COUNT (CASE WHEN CustomerCode like 'CAS%' and Deleted=0 and CashAccount=1 THEN CustomerID END )) as 'Cash Account' 
From Customer


--
Chandu

Edited by - bandi on 09/04/2013 06:29:58
Go to Top of Page

VeeranjaneyuluAnnapureddy
Posting Yak Master

India
164 Posts

Posted - 09/04/2013 :  06:09:06  Show Profile  Reply with Quote
Select
(COUNT (CASE WHEN CustomerCode like 'TRC%' and Deleted = 0 THEN CustomerID END)) as 'Trade Account' ,
(COUNT (CASE WHEN CustomerCode not like 'TRC%' and Deleted=0 and CashAccount=0 THEN CustomerID END )) as 'Credit Account',
(COUNT (CASE WHEN CustomerCode like 'CAS%' and Deleted=0 and CashAccount=1 THEN CustomerID END )) as 'Cash Account'
From Customer


veeranjaneyulu
Go to Top of Page

phate06
Starting Member

16 Posts

Posted - 09/04/2013 :  06:09:42  Show Profile  Reply with Quote
Thank you Sir, If I could See you I would probably Kiss you
Go to Top of Page

phate06
Starting Member

16 Posts

Posted - 09/04/2013 :  06:24:25  Show Profile  Reply with Quote
Thank you Sir, If I could See you I would probably Kiss you
Go to Top of Page

phate06
Starting Member

16 Posts

Posted - 09/04/2013 :  06:24:57  Show Profile  Reply with Quote
Thank you Sir, If I could See you I would probably Kiss you
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2202 Posts

Posted - 09/04/2013 :  06:30:29  Show Profile  Reply with Quote
Welcome

--
Chandu
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.05 seconds. Powered By: Snitz Forums 2000