Add value to return result set.

  • I was wondering if I can contruct a stored procedure that can add a value to to resultset. In my case I would like to add the value 'ALL' Thanks for any help.

  • Care to show us what you asking?

  • Yes like i said I have a stored procedure that I execute to return a resultset. This resultset is simply to provide a list of states to the user.However there is a value that is not in the returned resultset that i need. For Example the value ALL.

  • Try to use UNION or UNION ALL statement. (For details please see BOL or provide some more details on what you're trying to do).



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • No, that isn't what I asked for. Show what you are trying to accomplish. What code have you written so far, and you actually want.

  • Select * from States. Then I want to add the value ALL to the resultset.

  • So it sounds like i would need to create a new table just to hold the value ALL?

  • ronaldkrex (2/5/2010)


    Select * from States. Then I want to add the value ALL to the resultset.

    Not really sure if you want this:

    select 'ALL',StateName from States

    or this

    select StateName from States

    union all

    select 'ALL'

    Hard to tell as you haven't shown what you want.

  • Thanks it worked great however I lost my column name. Can you tell me how to rename it from No column name to depatment.

  • Show me your code.

  • select 'ALL'

    union all

    SELECT distinct Department FROM dbo.tblReportData

  • ronaldkrex (2/5/2010)


    select 'ALL'

    union all

    SELECT distinct Department FROM dbo.tblReportData

    select 'ALL' as Department

    union all

    SELECT distinct Department FROM dbo.tblReportData

  • I was just going to tell you I figure it out. You have Been very very helpful. Thank you so much. What do I do to vote for you or give you credit for answering my question?

  • ronaldkrex (2/5/2010)


    I was just going to tell you I figure it out. You have Been very very helpful. Thank you so much. What do I do to vote for you or give you credit for answering my question?

    This web site doesn't work that way... we've evolved:w00t:

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

Viewing 14 posts - 1 through 13 (of 13 total)

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