| Author |
Topic |
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2007-11-27 : 09:01:15
|
Hi,my code looks like thisDeclare @Temp Table(id_customer int, id_product varchar(10))Insert Into @Temp(id_customer, id_product) Values(12, 'ABC104')Insert Into @Temp(id_customer, id_product) Values(12, 'ABC143')Insert Into @Temp(id_customer, id_product) Values(12, 'ABC103')Insert Into @Temp(id_customer, id_product) Values(13, 'ABC102')Insert Into @Temp(id_customer, id_product) Values(14, 'ABC101')Insert Into @Temp(id_customer, id_product) Values(15, 'AABC10')Insert Into @Temp(id_customer, id_product) Values(15, 'AABC11')select * from @TempDeclare @results VarChar(100) Select @results = IsNull(@results + '; ', '') + IsNull(id_product, '') From @Tempwhere id_customer = 12 Select @results as all_products and when i run "Select @results as all_products" what shall i do to get id_customer along? if i do "select id_customer, @results as all_products" I get error in return :(thank you |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-11-27 : 09:16:28
|
| [code]select id_customer, @results as all_productsfrom @Temp[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2007-11-27 : 09:30:43
|
| Harsh Athalye: cleary it was a typing mistake :)PeterNeo: thank you; would you be so kind and give me all the code :) it seems, that it doesn't work if I do[CODE]Declare @Temp Table(id_customer int, id_product varchar(10))Insert Into @Temp(id_customer, id_product) Values(12, 'ABC104')Insert Into @Temp(id_customer, id_product) Values(12, 'ABC143')Insert Into @Temp(id_customer, id_product) Values(12, 'ABC103')Insert Into @Temp(id_customer, id_product) Values(13, 'ABC102')Insert Into @Temp(id_customer, id_product) Values(14, 'ABC101')Insert Into @Temp(id_customer, id_product) Values(15, 'AABC10')Insert Into @Temp(id_customer, id_product) Values(15, 'AABC11')SELECT DISTINCT id_customer,((SELECT ';' + IsNull(id_product, '') FROM @Temp WHERE id_customer = t.id_customer FOR XML PATH('')), 1, 1, '') AS all_productsFROM @Temp t[/CODE] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-27 : 09:45:12
|
| Read adam's articleMadhivananFailing to plan is Planning to fail |
 |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2007-11-28 : 00:26:16
|
| Hi u missed the STUFF key word in u r stmtDeclare @Temp Table(id_customer int, id_product varchar(10))Insert Into @Temp(id_customer, id_product) Values(12, 'ABC104')Insert Into @Temp(id_customer, id_product) Values(12, 'ABC143')Insert Into @Temp(id_customer, id_product) Values(12, 'ABC103')Insert Into @Temp(id_customer, id_product) Values(13, 'ABC102')Insert Into @Temp(id_customer, id_product) Values(14, 'ABC101')Insert Into @Temp(id_customer, id_product) Values(15, 'AABC10')Insert Into @Temp(id_customer, id_product) Values(15, 'AABC11')SELECT DISTINCT id_customer,STUFF((SELECT ';' + IsNull(id_product, '') FROM @Temp WHERE id_customer = t.id_customer FOR XML PATH('')), 1, 1, '') AS all_productsFROM @Temp t |
 |
|
|
|
|
|