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
 A SELECT statement with just sub-selects?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Maverick_
Posting Yak Master

107 Posts

Posted - 11/06/2012 :  05:49:33  Show Profile  Reply with Quote
Hi all,

Is it possible to write a SELECT statement with just sub-selects? I don't need a FROM for a query I am writing.

E.g.

SELECT

(SELECT count(job.job_number)
FROM
job,
job_status_log
WHERE
job.job_number = job_status_log.job_number AND
job.job_log_number = job_status_log.job_log_number AND
job.job_status_flag = 'C' AND
job_status_log.status_code IN ('J020', 'J020', 'J040')) as Orders_Issued_Awaiting_Completion

DonAtWork
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 11/06/2012 :  06:26:32  Show Profile  Reply with Quote
So, why is this a nested select? Just select your count. Also, you should really use the LEFT JOIN, INNER JOIN syntax instead of joining in the where clause.








How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2206 Posts

Posted - 11/06/2012 :  06:26:35  Show Profile  Reply with Quote
It is not possible for sub-query..

You have to write FROM clause to get sub-query...

For your query, no need of outer SELECT at all know.......?

--
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