Combining two fields into 1

  • Good day,

    I have a stored proc that returns information pertaining to orders, and this gets run through a report. If the order info has more than 1 hold type (credit hold or direct hold) then the report duplicates the order info for each of these hold types.

    I want to be able to combine these 2 or more hold types into the same row, so instead of there being 2 rows (1 with credit hold and 1 with direct hold) there should be 1 row for the specific item number, with the results being presented like credit hold/direct hold.

    Anybody have any ideas on what i can do?

    Thanks!

  • you need to get an idea of how many different hold types there and then use a cross tab structure. Something like

    max(case when hold = 'credit' then hold else '' end)

    max(case when hold = 'Direct' then hold else '' end)

    group by orders

    www.sql-library.com[/url]

  • check out http://www.sqlservercentral.com/columnists/cherring/replacingcursorsandwhileloops.asp

     

    specifically the Replacing the Outer Cursor code sample.  The code needs a local variable to hold the strings, but you can concatenate the whole list into a single field.

  • Post your table structure with sample data. It is difficult for us to advice you without knowledge of your structure

  • case when MIN(Type) = MAX(Type) then MIN(Type) else Min(type) + '/' + MAX(Type) end

    _____________
    Code for TallyGenerator

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

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