Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bhushan_juare
Starting Member
45 Posts |
Posted - 2013-02-04 : 07:56:21
|
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
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-04 : 08:09:23
|
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 ModelSizeForSomeXFROM TheTable;-- Or this?SELECT model_size, model_type, actual_qty, process_qty, order_type,FROM TheTableWHERE order_type = 'Some X' |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-04 : 12:22:28
|
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 MVPhttp://visakhm.blogspot.com/ |
|
|
bhushan_juare
Starting Member
45 Posts |
Posted - 2013-02-05 : 00:02:17
|
Yes, you are right but thing is that I have to use Select in Select to get data set for 'Some X' Reason isSELECT 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..? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-05 : 00:05:33
|
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 MVPhttp://visakhm.blogspot.com/ |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-05 : 08:04:47
|
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 TheTableWHERE 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 |
|
|
srimami
Posting Yak Master
160 Posts |
Posted - 2013-02-05 : 08:37:07
|
Hi Bhushan,I think you are referring to subqueries when you say select in select; please follow James reply for your "select in select". |
|
|
|
|
|
|
|