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 |
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-03-18 : 09:50:27
|
| Hello i need to concatenate the string in a row for DESC with another row for the same group by variable Valuethis is my tableValue SEQ N DESC SHORT DESCA4422 00100 3 OSTOMY ABSORBENT OSTOMYA4422 00200 4 THICKEN LIQUID A4423 00100 3 OSTOMY POUCH, OSTOMYA4423 00200 4 PIECE), EACHA4424 00100 3 OSTOMY POUCH, OSTOMYA4425 00100 3 OSTOMY POUCH, OSTOMY A4425 00200 4 FILTER (2 PIECE SYSTEM)This is what i wantValue SEQ N DESC SHORT DESA4422 00100 3 OSTOMY ABSORBENT THICKEN LIQUID OSTOMYA4423 00100 3 OSTOMY POUCH, PIECE), EACH OSTOMYA4424 00100 3 OSTOMY POUCH, DRAINABLE, WITH BARRIEROSTOMY A4425 00100 3 OSTOMY POUCH, FILTER (2 PIECE SYSTEM)i need to retrieve just Value seq desc and Short desc column in my tableAny helpTHanks |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-18 : 10:06:07
|
| Could you make this A4422 00100 3 OSTOMY ABSORBENT OSTOMYA4422 00200 4 THICKEN LIQUID A4423 00100 3 OSTOMY POUCH, OSTOMYA4423 00200 4 PIECE), EACHA4424 00100 3 OSTOMY POUCH, OSTOMYA4425 00100 3 OSTOMY POUCH, OSTOMY A4425 00200 4 FILTER (2 PIECE SYSTEM)into usable sample data? It isn't obvious which value is the DESC and which is the Short DescFor ExampleSELECT 'A4422','00100', 3, 'OSTOMY','ABSORBENT OSTOMY' UNION ALLSELECT etc.JimEveryday I learn something that somebody else already knew |
 |
|
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-03-18 : 11:13:42
|
| I am sorry, My bad . Thanks. The seq num increases from 00100 to 00200 if there are two line of DESC entry for that Value in the next record and so on to 00300 for 3 entries, 00400 etc.Value SEQ N DESC SHORT DESCA4422 00100 3 OSTOMY ABSORBENT OSTOMYA4422 00200 4 THICKEN LIQUIDA4423 00100 3 OSTOMY POUCH, OSTOMYA4423 00200 4 PIECE), EACHA4424 00100 3 OSTOMY POUCH, OSTOMYA4425 00100 3 OSTOMY POUCH, OSTOMYA4425 00200 4 FILTER (2 PIECE SYSTEM)This is what i wantValue SEQ N DESC SHORT DESA4422 00100 3 OSTOMY ABSORBENT THICKEN LIQUID OSTOMYA4423 00100 3 OSTOMY POUCH, PIECE), EACH OSTOMYA4424 00100 3 OSTOMY POUCH, DRAINABLE, WITH BARRIER OSTOMYA4425 00100 3 OSTOMY POUCH, FILTER (2 PIECE SYSTEM) OSTOMY |
 |
|
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-03-18 : 11:14:17
|
| Crapfor some reson it is not formatiing the way i like. gimme a min |
 |
|
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-03-18 : 11:17:19
|
| I am sorry, My bad . Thanks. The seq num increases from 00100 to 00200 if there are two line of DESC entry for that Value in the next record and so on to 00300 for 3 entries, 00400 etc. i am using --- for spacesValue SEQ --N DESC-----------------------------------SHORT DESCA4422 00100 3 OSTOMY ABSORBENT ----------------------OSTOMYA4422 00200 4 THICKEN LIQUIDA4423 00100 3 OSTOMY POUCH, -------------------------OSTOMYA4423 00200 4 PIECE), EACHA4424 00100 3 OSTOMY POUCH, -------------------------OSTOMYA4425 00100 3 OSTOMY POUCH, -------------------------OSTOMYA4425 00200 4 FILTER (2 PIECE SYSTEM)This is what i wantValue SEQ N DESC--------------------------------------------SHORT DESA4422 00100 3 OSTOMY ABSORBENT THICKEN LIQUID-----------------OSTOMYA4423 00100 3 OSTOMY POUCH, PIECE), EACH----------------------OSTOMYA4424 00100 3 OSTOMY POUCH, DRAINABLE, WITH BARRIER-----------OSTOMYA4425 00100 3 OSTOMY POUCH, FILTER (2 PIECE SYSTEM)-----------OSTOMY |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-18 : 11:20:28
|
| My suggestion would have been betterSELECT 'A4422','00100', 3, 'OSTOMY','ABSORBENT OSTOMY' UNION ALLSELECT etc.Unless you're trying to make me do more so you can do less!Jim Read thishttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxEveryday I learn something that somebody else already knew |
 |
|
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-03-18 : 11:35:46
|
| Jim, that is the table structure i have. Your suggestion never came to my mind. But i hope you understand what i am trying to get? |
 |
|
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-03-18 : 15:30:56
|
| I used this function to do thisCREATE FUNCTION recursive ( @cid VARCHAR(5), @i INT )RETURNS VARCHAR(8000) AS BEGIN DECLARE @r VARCHAR(8000), @l VARCHAR(8000) SELECT @i = @i - 1, @r = DESC + ' ' FROM TABLE p1 WHERE VALUE = @cid AND @i = ( SELECT COUNT(*) FROM TABLE p2 WHERE p2.VALUE = p1.VALUE AND p2.SEQ <= p1.SEQ) ; IF @i > 0 BEGIN EXEC @l = dbo.recursive @cid, @i ; SET @r = @l + @r ;ENDRETURN @r ;END SELECT VALUE, dbo.recursive( VALUE, COUNT(DESC) ) as NEW_DESC FROM TABLEGROUP BY VALUE; |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|
|