select statement

  • hi

    i am having trouble in select stm

    select "heading1" = case when (condition) then

    item1

    else item1

    end

    from tablename

    in the else part i am getting so many item1 like

    item1

    item1

    item1........

    i just want one item1 ,not the duplicate

  • It's hard to say without a proper example with DDL and sample data. You've got item1 in both sides of your CASE .. ELSE expression.

    But perhaps a "SELECT TOP 1" is what you're looking for.

    Converting oxygen into carbon dioxide, since 1955.
  • ill come in and say it could be a select distinct... but even so DDL (Create table statements) and sample data (Insert statements) will be incredibly helpful in this case

    help us help you and see the link in my signature if you need help on how to post the ddl and sample data.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • i m getting values like this

    null

    null

    item1

    null

    null

    how to tremove null

  • use WHERE clause:

    WHERE [value] IS NOT NULL

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • If you really want help, help us. Please post the CREATE TABLE statement(s) for the table(s) involved, sample data as a series of INSERT INTO statements for the table(s), and your expected results based on the sample data you provide.

  • i did.stil its not working

  • hbtkp (4/12/2012)


    i did.stil its not working

    with out seeing your table structure the sample data in that table and the query you are trying to run we can go no further. if you would still like help, help us help you and see the link in my signature for how to post DDL and Sample data.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • You already have another thread on this same topic. http://www.sqlservercentral.com/Forums/Topic1281058-392-1.aspx You didn't get the answer you wanted there, because you didn't provide the requested information. Starting a new thread isn't going to change that.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • i dont have this thread before.

    yes i need to get same values in else also

  • hbtkp (4/12/2012)


    i dont have this thread before.

    yes i need to get same values in else also

    drew.allen is saying that you have asked a similar question in the above posted thread which you opened before this one. and when you did not get your answer you opened another asking the same question a different way and getting the same result. "Post sample DDL and Data" please pick a thread and post the table deffinition scripts and the sample inserts and you will get your answer so much quicker. please read the link in my signature for how to post the DDL and sample data.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • Here is the complete solution based on the information you have provided so far.

    select ? from ?

    Why are you so stubborn about posting ddl and sample data? If you would just post this you would get help. The help would be quick and the solution even quicker.

    You have not provided enough information for anybody to have a chance at helping you.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (4/12/2012)


    Why are you so stubborn about posting ddl and sample data?

    I've come to the conclusion that he's not really interested in answers. He's only interested in monopolizing the conversation.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • drew.allen (4/12/2012)


    Sean Lange (4/12/2012)


    Why are you so stubborn about posting ddl and sample data?

    I've come to the conclusion that he's not really interested in answers. He's only interested in monopolizing the conversation.

    Drew

    WWSD -- Probably tell us to leave the thread.

  • Lynn Pettis (4/12/2012)


    drew.allen (4/12/2012)


    Sean Lange (4/12/2012)


    Why are you so stubborn about posting ddl and sample data?

    I've come to the conclusion that he's not really interested in answers. He's only interested in monopolizing the conversation.

    Drew

    WWSD -- Probably tell us to leave the thread.

    nah see how long we can go with out getting the DDL and sample data and see if we can break 100 posts.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

Viewing 15 posts - 1 through 15 (of 17 total)

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