In Query - All rows with same status

  • Hello Everyone. This might be very simple, but need some help. I get records from a query whose status is "Marked". I need another column to be added to result set which just says "Marked" for every record. Is that possible in query?:exclamationmark::exclamation:

  • chindilog (10/28/2015)


    Hello Everyone. This might be very simple, but need some help. I get records from a query whose status is "Marked". I need another column to be added to result set which just says "Marked" for every record. Is that possible in query?:exclamationmark::exclamation:

    Sure. Just add [AnotherColumn] = 'Marked' to your SELECT list.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • I get it. All rows shows marked but column name shows "constant", how do I change "constant" to "status"?

    SELECT 'Packed', so.num AS ordernum, so.customercontact,

    so.dateissued, so.datecreated, so.datecompleted

    FROM ship

    LEFT JOIN so ON so.id = ship.soid

    WHERE ship.statusid = 20

  • chindilog (10/28/2015)


    I get it. All rows shows marked but column name shows "constant", how do I change "constant" to "status"?

    SELECT 'Packed', so.num AS ordernum, so.customercontact,

    so.dateissued, so.datecreated, so.datecompleted

    FROM ship

    LEFT JOIN so ON so.id = ship.soid

    WHERE ship.statusid = 20

    Use REPLACE() function or a CASE structure. Both are well documented in Books Online (SQL Server Help).

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Is it the name of the column in your result set you want to change? If so, do it in the way Chris first suggested, or in the way you've done for your ordernum column. Best not to mix the two, though.

    John

  • A simple - "Marked" as status , worked. Thanks so much.

  • CAST('Marked' as varchar(20)) AS [XYZ]

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

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