dbTalk Databases Forums  

Combine Multiple Records

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Combine Multiple Records in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mike
 
Posts: n/a

Default Combine Multiple Records - 08-09-2004 , 06:57 PM






I have a table that has comments in it, but the way they are formatted isn't
very easy to work with. For Example:

Comment# Seq# Comment
12345 1 Please ship this
12345 2 order today.

What is shown is comment # 12345, which has 2 records (They can have many)
to make the comment "Please ship this order today"

I would like to use a DTS job to transform this comment into one record and
eliminate the seq #. The above would become:

Comment# Comment
12345 Please ship this order today.

Does anyone know how to accomplish this?

Thanks,
Mike



Reply With Quote
  #2  
Old   
Ilya Margolin
 
Posts: n/a

Default Re: Combine Multiple Records - 08-10-2004 , 07:51 AM






Mike,

You would have to do it in a loop or in a cursor. Here is a loop example:

Declare @MaxSeg smallint
,@Counter smallint

Select @MaxSeg = Max([Seq#]) From <Comments table>

Set @Counter = 1

While @Counter <= @MaxSeg Begin

Set @Counter = @Counter + 1

Update c1
Set Comment = Comment + c2.Comment
From <Comments table> c1
Inner Join <Comments table> c2
On c1.[Comment#] = c2.[Comment#]
Where c1.[Seq#] = 1
And c2.[Seq#] = @Counter

Delete <Comments table>
Where [Seq#] = @Counter
End

The example will stock all comments into Seq# = 1 rows and get rid of the
rest of Seq#. The code was not tested.

Ilya

"Mike" <mbaith (AT) yahoo (DOT) com> wrote

Quote:
I have a table that has comments in it, but the way they are formatted
isn't
very easy to work with. For Example:

Comment# Seq# Comment
12345 1 Please ship this
12345 2 order today.

What is shown is comment # 12345, which has 2 records (They can have many)
to make the comment "Please ship this order today"

I would like to use a DTS job to transform this comment into one record
and
eliminate the seq #. The above would become:

Comment# Comment
12345 Please ship this order today.

Does anyone know how to accomplish this?

Thanks,
Mike





Reply With Quote
  #3  
Old   
Mike
 
Posts: n/a

Default Re: Combine Multiple Records - 08-10-2004 , 12:24 PM



How would I execute this code from a DTS job?



Reply With Quote
  #4  
Old   
Ilya Margolin
 
Posts: n/a

Default Re: Combine Multiple Records - 08-11-2004 , 08:39 AM



Mike,

You make it an Execute SQL task with that code or with a stored procedure
made out of the code.

Ilya

"Mike" <mbaith (AT) yahoo (DOT) com> wrote

Quote:
How would I execute this code from a DTS job?





Reply With Quote
  #5  
Old   
Ilya Margolin
 
Posts: n/a

Default Re: Combine Multiple Records - 08-11-2004 , 08:42 AM



....make sure the Comment column has enough space in it.

Ilya

"Ilya Margolin" <ilya_no_spam_ (AT) unapen (DOT) com> wrote

Quote:
Mike,

You would have to do it in a loop or in a cursor. Here is a loop example:

Declare @MaxSeg smallint
,@Counter smallint

Select @MaxSeg = Max([Seq#]) From <Comments table

Set @Counter = 1

While @Counter <= @MaxSeg Begin

Set @Counter = @Counter + 1

Update c1
Set Comment = Comment + c2.Comment
From <Comments table> c1
Inner Join <Comments table> c2
On c1.[Comment#] = c2.[Comment#]
Where c1.[Seq#] = 1
And c2.[Seq#] = @Counter

Delete <Comments table
Where [Seq#] = @Counter
End

The example will stock all comments into Seq# = 1 rows and get rid of the
rest of Seq#. The code was not tested.

Ilya

"Mike" <mbaith (AT) yahoo (DOT) com> wrote in message
news:ekOCiymfEHA.596 (AT) TK2MSFTNGP11 (DOT) phx.gbl...
I have a table that has comments in it, but the way they are formatted
isn't
very easy to work with. For Example:

Comment# Seq# Comment
12345 1 Please ship this
12345 2 order today.

What is shown is comment # 12345, which has 2 records (They can have
many)
to make the comment "Please ship this order today"

I would like to use a DTS job to transform this comment into one record
and
eliminate the seq #. The above would become:

Comment# Comment
12345 Please ship this order today.

Does anyone know how to accomplish this?

Thanks,
Mike







Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.