Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to use Select within select in the same Select statement..?? Expand / Collapse
Author
Message
Posted Monday, February 04, 2013 5:53 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 12:14 AM
Points: 62, Visits: 358
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
Post #1415253
Posted Monday, February 04, 2013 6:15 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 3:05 AM
Points: 37,675, Visits: 29,927
Case statement is probably what you're looking for, but not enough information to be sure.

All this is in one table? What do you want the model size column to show for rows that have other order types?



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1415260
Posted Monday, February 04, 2013 6:16 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 12:53 AM
Points: 150, Visits: 1,026
Why case? You need a simple select and a where condition or I don't understand your question. Post example data and result then it will be easier
Post #1415261
Posted Monday, February 04, 2013 10:17 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 12:14 AM
Points: 62, Visits: 358
To show which model_type is coming in next phase and so on for production...
Hence i have to show that field also along with actual_qty..
Post #1415567
Posted Monday, February 04, 2013 10:31 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, May 18, 2013 6:46 PM
Points: 1,074, Visits: 1,076
bhushan_juare (2/4/2013)
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


See that's how your statement look like
CREATE TABLE #Fields (model_size INT, model_type VARCHAR(10), actual_qty INT,process_qty, order_type Char(3) )
-- display all fields + modelsize where ordertype='X'
Select model_size, model_type, actual_qty, process_qty, order_type from #Fields
Where order_type = 'Some X'

You must give out the exact information to get the solution ..
Give the table information DDL's like create table statements; and the sample data and the resultset data that you are looking for ..


~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one
Post #1415571
Posted Monday, February 04, 2013 10:38 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, May 18, 2013 6:46 PM
Points: 1,074, Visits: 1,076
bhushan_juare (2/4/2013)
Hi All,
I am unable to do that using Case statement..
Bhushan


that's how you implement case statement


CREATE TABLE #Fields
(
MODEL_SIZE INT,
MODEL_TYPE VARCHAR(10),
ACTUAL_QTY INT,
PROCESS_QTY INT,
ORDER_TYPE CHAR(3)
)

insert into #Fields values (1,'abc',10,5,'t'),
(2,'bcd',10,5,'y'),(3,'abcd',10,5,'z')

SELECT MODEL_SIZE,
MODEL_TYPE,
ACTUAL_QTY,
PROCESS_QTY,
ORDER_TYPE,
( CASE
WHEN ORDER_TYPE = 't' THEN 'new'
ELSE 'existing'
END )AS attribinfo
FROM #Fields



~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one
Post #1415572
Posted Tuesday, February 05, 2013 2:31 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:18 AM
Points: 2,211, Visits: 4,164
bhushan_juare (2/4/2013)
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


Your explanation is not very clear and hence gives rise to confusions
Please provide DDL of the tables involved along with some sample data and the expected results
This will help us give you a tested answer
If you don't know how to do this, read the link in my signature



Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1415656
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse