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)
 How to use Select within select in the same Select
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bhushan_juare
Starting Member

45 Posts

Posted - 02/04/2013 :  07:56:21  Show Profile  Reply with Quote
Hi All,

I Have table where it includes fields model_size, model_type, actual_qty, process_qty, order_type. Now I want to display all fields + model_size who has order_type = 'Some X' but I am unable to do that using Case statement..

All suggestion are welcome..

Thanks..

Bhushan

James K
Flowing Fount of Yak Knowledge

3659 Posts

Posted - 02/04/2013 :  08:09:23  Show Profile  Reply with Quote
Is one of these what you are looking for?
-- THIS?
SELECT model_size, model_type, actual_qty, process_qty, order_type,
CASE WHEN order_type = 'Some X' THEN model_size END AS ModelSizeForSomeX
FROM TheTable;

-- Or this?
SELECT model_size, model_type, actual_qty, process_qty, order_type,
FROM TheTable
WHERE order_type = 'Some X'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/04/2013 :  12:22:28  Show Profile  Reply with Quote
best thing would be to put some sample data and required output to give us an idea of what exactly you're trying to achieve


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bhushan_juare
Starting Member

45 Posts

Posted - 02/05/2013 :  00:02:17  Show Profile  Reply with Quote
Yes, you are right but thing is that I have to use Select in Select to get data set for 'Some X' Reason is
SELECT model_size, model_type, actual_qty, process_qty, order_type--> Gave me result set for all 'Some X', 'Some Y', 'Some Z'... Now at the same time i need result set for all 'Some X' in that select...
I can't achieve this using Case statement...
Any suggestion on that..?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/05/2013 :  00:05:33  Show Profile  Reply with Quote
can you show some sample data and explain what output you want out of it? Without that we cant understand what you're asking for

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3659 Posts

Posted - 02/05/2013 :  08:04:47  Show Profile  Reply with Quote
The thing that I am not following is the concept of "select in select" that you are using. Using WHERE clause (as I have in my second query that I posted earlier) is one way of filtering the data to get subset. Perhaps you mean that the 'Some X' itself comes from another query? If that is the case, something like shown below may be what you need:
SELECT model_size, model_type, actual_qty, process_qty, order_type,
FROM TheTable
WHERE order_type IN (SELECT t.some_x FROM TheOtherTable t);
But, the best way to get accurate responses is what Visakh suggested - post some sample data along with the results you are looking for. This article might help in posting: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

srimami
Posting Yak Master

160 Posts

Posted - 02/05/2013 :  08:37:07  Show Profile  Reply with Quote
Hi Bhushan,

I think you are referring to subqueries when you say select in select; please follow James reply for your "select in select".
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.11 seconds. Powered By: Snitz Forums 2000