How to use Select within select in the same Select statement..??

  • [font="Courier New"]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[/font]

  • 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, MVP, M.Sc (Comp Sci)
    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
  • 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

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

  • bhushan_juare (2/4/2013)


    [font="Courier New"]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[/font]

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

  • bhushan_juare (2/4/2013)


    [font="Courier New"]Hi All,

    I am unable to do that using Case statement..

    Bhushan[/font]

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

  • bhushan_juare (2/4/2013)


    [font="Courier New"]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[/font]

    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/

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply