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 |
|
obsoletedude
Starting Member
31 Posts |
Posted - 2008-08-20 : 17:13:12
|
| How can I coalesce data from a TmpTable.Because of our database structure, I need to run separate quries using joins to return the final results. I need to take those final results and coalesce one of the columns based on another column.Example of ##TmpTableRecordID CompID12 1512 1612 1713 1814 1914 20Returned results:RecordID CompID12 15,16,1713 1814 19,20I was given assistance here before on using a function to perform the coalesce and it works like a dream, however, the function will not work when using a ##TmpDatabase.If needed, I can place the script that I am using to create the ##TmpTable, but because of the complexity, there are 4 actual tables used, using joins, to create my one ##TmpTable. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
obsoletedude
Starting Member
31 Posts |
Posted - 2008-08-21 : 10:25:53
|
| cross apply doesn't really work for what I'm trying to do. Here is the script to get the info into my ##TmpTable:select * into ##TmpReport from stringvalues where FK_FieldID = '1416'select * into ##TmpCompJobID from stringvalues where FK_FieldID = '2970'select * into ##TmpLandID from integervalues where FK_FieldID = '2958'select * into ##TmpCompID from stringvalues where FK_FieldID = '898'select a.FK_ReferenceID as CompLinkID,a.value as JobID,b.value as LandID,c.FK_ReferenceID as RecordID,d.FK_referenceID as CompID from ##TmpCompJobID ainner join ##TmpLandID b on a.FK_ReferenceID = b.FK_ReferenceIDinner join ##TmpReport c on a.value = c.valueinner join ##TmpCompID d on d.value = b.valuedrop table ##TmpReportdrop table ##TmpCompJobIDdrop table ##TmpLandIDdrop table ##TmpCompIDThe CompID field will be the unique values, based on the RecordID, and it is the CompID field I need to have returned as a comma separated value. (The other columns are brought in as they are used to ultimately sych everything. |
 |
|
|
|
|
|
|
|