Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
osupratt
Posting Yak Master
238 Posts |
Posted - 2010-10-25 : 19:20:57
|
I have the following query:SELECT'COM' AS LineDetailType,NULL AS WorkLocation, NULL AS CommentTickNumDate, NULL AS MiscCodeUNION ALLSELECT 'INV' AS LineDetailType, hdr.WorkLocation, CONVERT(NVARCHAR(11),hdr.Date)+' '+ hdr.DailyWorkTicketNumber AS CommentTickNumDate, inv.MiscCodeFROM dbo.MercerDailyWorkTicketHdr AS hdr INNER JOIN dbo.MercerDailyWorkTicketInv AS inv ON hdr.DailyWorkTicketNumber = inv.DailyWorkTicketNumberWHERE (hdr.Misc_Text_Field4 = 'testinv1')It gives me this output:LineDetailType WorkLocation CommentTickNumDate MiscCodeCOM NULL NULL NULLINV MWSBOW Oct 24 2010 TESTINV1 10RIGINV MWSBOW Oct 24 2010 TESTINV2 10RIG PACKINV MWSBOW Oct 24 2010 TESTINV3 10BOPINV MWSBOW Oct 24 2010 TESTINV3 10RIGINV MWSBOW Oct 24 2010 TESTINV4 10CTINV MWSBOW Oct 24 2010 TESTINV4 10BOPINV MWSBOW Oct 24 2010 TESTINV4 10RIGXTO PACKINV MWSBOW Oct 24 2010 TESTINV5 10TRUCKINGThe 'COM' on the 1st row is for Comment Line. The 'INV' is for invoice detail line. I am needing to combine all the CommentTickNumDate text data from the INV lines and place it in the CommentTickNumDate field of the COM row. Here is what the CommentTickNumDate field should look like for the output above for Row 1 or COM line:Oct 24 2010 TESTINV1; Oct 24 2010 TESTINV2; Oct 24 2010 TESTINV3; Oct 24 2010 TESTINV4; Oct 25 2010 TESTINV5I could do this if there were only so many rows or tickets going onto this Invoice; however, there can be 1 INV line or 40 INV lines or even 100 INV lines. Would anyone know of a way to accomplish this without creating 100 columns and then concantenating them all? |
|
Annn123
Starting Member
1 Post |
Posted - 2010-10-26 : 00:00:09
|
unspammed |
 |
|
osupratt
Posting Yak Master
238 Posts |
Posted - 2010-10-27 : 10:39:16
|
Thanks for trying to sell me boots???Anyhow, have figured this post out. |
 |
|
lili123
Starting Member
2 Posts |
Posted - 2010-12-06 : 02:16:04
|
unspammed |
 |
|
lili123
Starting Member
2 Posts |
Posted - 2010-12-06 : 02:18:58
|
unspammed |
 |
|
|
|
|