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 |
|
rternier
Starting Member
44 Posts |
Posted - 2007-07-03 : 14:47:12
|
| I'm not sure if this can be done...I have a Table:FKID,ReferenceName, Value====================1, System.TextBox, 122, System.TextArea, HI, my name is Ryan3, System.ListBox, 13, System.ListBox, 23, System.ListBox, 43, System.ListBox, 5I want to take the System.Listbox rows and change it to:3, System.ListBox, "1, 2, 4, 5"Now, this would be so easy if I could pass a table into a Function, but I'm not sure that's possible. Is it? |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
|
rternier
Starting Member
44 Posts |
Posted - 2007-07-03 : 17:19:05
|
| I looked at it but I can't see it :PI'm not an expert at SQL so my knowledge is somewhat limited. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-07-04 : 04:20:51
|
try this. maybe you'll have to group differently but it should give you an idea.select fkid, referenceName, (SELECT Value + ', ' as [text()] FROM YourTable GROUP BY fkid, referenceName ORDER BY Value FOR XML PATH('')) as listOfValuesfrom YourTable_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
rternier
Starting Member
44 Posts |
Posted - 2007-07-04 : 14:31:56
|
| THanks, I worked with that and I got closer to what I need:---------------INSERT INTO @LV(FieldID, ReferenceName, CSV) SELECT f.FieldID, f.ReferenceName, (SELECT CONVERT(VarChar(MAX),FLR.[FieldListValueID]) + ', ' FROM [Form].[Fields] F INNER JOIN [Form].FieldListValues FLV ON FLV.FieldID = F.FieldID INNER JOIN [Item].[ItemDetailFieldListRecords] FLR ON FLV.FieldListValueID = FLR.FieldListValueID WHERE FLR.ItemDetailID = @ItemDetailID ORDER BY FLR.[FieldListValueID] FOR XML PATH('')) as listOfValues FROM [Form].[Fields] F INNER JOIN [Form].FieldListValues FLV ON FLV.FieldID = F.FieldID INNER JOIN [Item].[ItemDetailFieldListRecords] FLR ON FLV.FieldListValueID = FLR.FieldListValueID WHERE FLR.ItemDetailID = @ItemDetailID ------------------(4 row(s) affected)FieldID ReferenceName CSV-----------4 test.DropDown 5, 8, 9, 10, 6 test.ListBox 5, 8, 9, 10, 6 test.ListBox 5, 8, 9, 10, 6 test.ListBox 5, 8, 9, 10,=======================A bit more tweaking to do. The original results were:FieldID ReferenceName Value----------1 test.Textbox test textbox2 test.TextArea Test TExt Area4 test.DropDown 55 test.Cascading 66 test.ListBox 106 test.ListBox 86 test.ListBox 97 test.Checkbox True9 test.Date 01/07/200710 test.Time 12:00 AM==========I can probably work on it from here. Thanks so much. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-04 : 14:34:23
|
| A DISTINCT keyword maybe?Peter LarssonHelsingborg, Sweden |
 |
|
|
rternier
Starting Member
44 Posts |
Posted - 2007-07-04 : 16:51:55
|
| Aye, I threw that in there which cleaned it up nicely. I also employed:SELECT LEFT(MyCsvList,LEN(MyCsvList)-1)FROM (SELECT(SELECT col + ', ' as [text()]FROM @tORDER BY col DESCFOR XML PATH('')) AS MyCsvList) zwhich was from a comment in the above link.Thanks for the help guys. |
 |
|
|
|
|
|
|
|