Result set with a predefined 1st line and last line...

  • Hello

    I have a query that generates a result set, on a daily bases whereby I need to include a predefined 1st line (010000000YYYMMDD00000000000000.....) which will indicate the beginning of the result set and 090000000..... which will indicate the last line of the result set.

    Can anyone help?

  • You could use a union ALL

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • I tried the union all but it gave me duplicate records

  • I have to ask. What is this for?

    Sounds like you are creating a flat file with a header. Yuk...

    I would create an SP that has a temp table you select your resultset data into with an identity column. Then select into a variable the Min value where the identity column = 1 and the max value where the identity column = SCOPE_IDENTITY(). Then you can concatenate the header string and print it (or use an OUTPUT variable), then select everything from the temp table.

    Gary Johnson
    Sr Database Engineer

  • Hello Gary

    You may need to expantiate on what you mean, the method you stated earlier, but I was able to get the desired output with the UNION and not the UNION ALL keyword which worked perfect for me (...thanks Chris!!!)

Viewing 5 posts - 1 through 4 (of 4 total)

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