Showing posts with label appreciate. Show all posts
Showing posts with label appreciate. Show all posts

Friday, March 23, 2012

script to combine multiple rows into a single row

Hi everyone,

I really appreciate if anyone could help me with this tricky problem
that I'm having. I'm looking for a sample script to combine data in
multiple rows into one row. I'm using sqlserver. This is how data is
stored in the table.

ID Color
111 Blue
111 Yellow
111 Pink
111 Green

This is the result that I would like to have.

ID Color
111 Blue, Yellow, Pink, Green

There is no definite number of colors per ID. I have to use ID to
group these colors into one row. Therefore, ID becomes a unique key
in the table.

Appreciate your help and time. Thank you in advancelie_valerie@.yahoo.com (Valerie) wrote in message news:<f4825946.0308141505.4c29ff89@.posting.google.com>...
> Hi everyone,
> I really appreciate if anyone could help me with this tricky problem
> that I'm having. I'm looking for a sample script to combine data in
> multiple rows into one row. I'm using sqlserver. This is how data is
> stored in the table.
> ID Color
> 111 Blue
> 111 Yellow
> 111 Pink
> 111 Green
> This is the result that I would like to have.
> ID Color
> 111 Blue, Yellow, Pink, Green
> There is no definite number of colors per ID. I have to use ID to
> group these colors into one row. Therefore, ID becomes a unique key
> in the table.
> Appreciate your help and time. Thank you in advance

The short answer is that you should consider doing this in your client
application. For a longer answer, have a look at the thread "newbie
sql query question" in this group from a day or two ago.

Simonsql

Monday, March 12, 2012

Script Help

Would really appreciate some help/ideas. The stored procedures for my
application are all saved to a folder in the file system of my deeloper work
station. What is the best way to loop through the folder and execute the sql
(create procedure...)in each file?
Thanks for any tipsOne method is to run your scripts with a FOR command from the command-prompt
that invokes OSQL. For example:
FOR %f IN (*.SQL) DO OSQL -i "%f" /E /S MyServer
Hope this helps.
Dan Guzman
SQL Server MVP
"Mardy" <Mardy@.discussions.microsoft.com> wrote in message
news:F9E35C8D-A44A-484A-A63B-D3571A908AF8@.microsoft.com...
> Would really appreciate some help/ideas. The stored procedures for my
> application are all saved to a folder in the file system of my deeloper
> work
> station. What is the best way to loop through the folder and execute the
> sql
> (create procedure...)in each file?
> Thanks for any tips|||FYI, I generally just copy all of the procedures to one file and run that:
COPY *.* SP.sql
But this will only work if you have a GO statement at the bottom of each.
"Dan Guzman" wrote:

> One method is to run your scripts with a FOR command from the command-prom
pt
> that invokes OSQL. For example:
> FOR %f IN (*.SQL) DO OSQL -i "%f" /E /S MyServer
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Mardy" <Mardy@.discussions.microsoft.com> wrote in message
> news:F9E35C8D-A44A-484A-A63B-D3571A908AF8@.microsoft.com...
>
>