| Author |
Topic |
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-24 : 04:09:16
|
| [code] HiI have table data like this after using UNPIVOTCOL1 COL2 COL3 1521M31P02 D_PERIOD_1 2.0001521M31P02 D_PERIOD_10 5.0001521M31P02 D_PERIOD_11 3.0001521M31P02 D_PERIOD_12 6.0001521M31P02 D_PERIOD_2 2.0001521M31P02 D_PERIOD_3 6.0001521M31P02 D_PERIOD_4 5.0001521M31P02 D_PERIOD_5 6.0001521M31P02 D_PERIOD_6 3.0001521M31P02 D_PERIOD_7 5.0001521M31P02 D_PERIOD_8 6.0001521M31P02 D_PERIOD_9 7.0001644M88P02 D_PERIOD_1 2.0001644M88P02 D_PERIOD_10 5.0001644M88P02 D_PERIOD_11 3.0001644M88P02 D_PERIOD_12 6.0001644M88P02 D_PERIOD_2 2.0001644M88P02 D_PERIOD_3 6.0001644M88P02 D_PERIOD_4 5.0001644M88P02 D_PERIOD_5 6.0001644M88P02 D_PERIOD_6 3.0001644M88P02 D_PERIOD_7 5.0001644M88P02 D_PERIOD_8 6.0001644M88P02 D_PERIOD_9 7.000But I want the output like this…COL1 COL2 COL3 1521M31P02 D_PERIOD_1 2.0001521M31P02 D_PERIOD_2 2.0001521M31P02 D_PERIOD_3 6.0001521M31P02 D_PERIOD_4 5.0001521M31P02 D_PERIOD_5 6.000 --GROUP ONE1521M31P02 D_PERIOD_6 3.0001521M31P02 D_PERIOD_7 5.0001521M31P02 D_PERIOD_8 6.0001521M31P02 D_PERIOD_9 7.0001521M31P02 D_PERIOD_10 5.0001521M31P02 D_PERIOD_11 3.0001521M31P02 D_PERIOD_12 6.0001644M88P02 D_PERIOD_1 2.0001644M88P02 D_PERIOD_2 2.0001644M88P02 D_PERIOD_3 6.0001644M88P02 D_PERIOD_4 5.0001644M88P02 D_PERIOD_5 6.000 --GROUP TWO1644M88P02 D_PERIOD_6 3.0001644M88P02 D_PERIOD_7 5.0001644M88P02 D_PERIOD_8 6.0001644M88P02 D_PERIOD_9 7.0001644M88P02 D_PERIOD_10 5.0001644M88P02 D_PERIOD_11 3.0001644M88P02 D_PERIOD_12 6.000 [/code]-------------------------R.. |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-07-24 : 04:37:45
|
| may be select * from table order by right(col2,1) |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-24 : 04:38:34
|
ORDER BY LEN(COL2) Hope can help...but advise to wait pros with confirmation... |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-07-24 : 04:39:46
|
| select * from table order by col1,right(col2,charindex('_',reverser(col2)-1),col3 |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-24 : 04:40:05
|
| Hi NagesNo, If you put means it will return all D_PERIOD_1 first and D_PERIOD_2 second...Correct me if am in wrong..-------------------------R.. |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-24 : 04:45:18
|
| Hi bklrI got this error...Conversion failed when converting the nvarchar value '1_DOIREP_D' to data type int.-------------------------R.. |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-24 : 04:47:36
|
| Hi waterduckOne record was changed 2.000 D_PERIOD_2 1521M31P026.000 D_PERIOD_3 1521M31P025.000 D_PERIOD_4 1521M31P026.000 D_PERIOD_5 1521M31P023.000 D_PERIOD_6 1521M31P025.000 D_PERIOD_7 1521M31P026.000 D_PERIOD_8 1521M31P027.000 D_PERIOD_9 1521M31P022.000 D_PERIOD_1 1521M31P025.000 D_PERIOD_10 1521M31P023.000 D_PERIOD_11 1521M31P026.000 D_PERIOD_12 1521M31P022.000 D_PERIOD_1 1644M88P022.000 D_PERIOD_2 1644M88P026.000 D_PERIOD_3 1644M88P025.000 D_PERIOD_4 1644M88P026.000 D_PERIOD_5 1644M88P023.000 D_PERIOD_6 1644M88P025.000 D_PERIOD_7 1644M88P026.000 D_PERIOD_8 1644M88P027.000 D_PERIOD_9 1644M88P025.000 D_PERIOD_10 1644M88P023.000 D_PERIOD_11 1644M88P026.000 D_PERIOD_12 1644M88P02-------------------------R.. |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-24 : 04:49:05
|
SELECT *FROM tableORDER BY col1, len(col2)this cannot? Hope can help...but advise to wait pros with confirmation... |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-24 : 04:53:22
|
[code]CREATE TABLE #Tempfun(col1 varchar(10),col2 varchar(10))INSERT INTO #Tempfun (col1, col2)SELECT '1','1' UNION ALLSELECT '1','2' UNION ALLSELECT '1','3' UNION ALLSELECT '1','11' UNION ALLSELECT '1','12' UNION ALLSELECT '1','13' UNION ALLSELECT '1','21' UNION ALLSELECT '1','22' UNION ALLSELECT '1','23' UNION ALLSELECT '2','1' UNION ALLSELECT '2','1' UNION ALLSELECT '2','1'SELECT *FROM #TempfunORDER BY col1, LEN(col2)DROP TABLE #Tempfun[/code]i try can oo x.X Hope can help...but advise to wait pros with confirmation... |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-07-24 : 04:55:33
|
| try thissmall correction inplace of bracketsselect * from table order by col1,right(col2,charindex('_',reverse(col2))-1),col3 |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-24 : 05:11:22
|
[code]SELECT *FROM #TempfunORDER BY col1, LEN(col2), col2[/code]sorry mistake been done Hope can help...but advise to wait pros with confirmation... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-24 : 05:35:00
|
| If D_PERIOD_ is fixed for col2, Order by len(col2),col2should workMadhivananFailing to plan is Planning to fail |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-24 : 05:35:57
|
| Hi bklrI was noticed inplace of brackets..that i have done change. But still the data is some mismatch order..friend-------------------------R.. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-24 : 05:36:15
|
| ororder by replace(col2,'D_PERIOD_','')*1MadhivananFailing to plan is Planning to fail |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-24 : 05:36:41
|
| hi waterduckIts working fine... thanks a lot friend..-------------------------R.. |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-24 : 05:37:41
|
| Hi bklrwe can discuss now ....Thanks friend-------------------------R.. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-24 : 05:53:38
|
What about my suggestions? MadhivananFailing to plan is Planning to fail |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-07-24 : 05:54:20
|
wahaha...first post that accept by people  Hope can help...but advise to wait pros with confirmation... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-24 : 05:54:55
|
quote: Originally posted by waterduck wahaha...first post that accept by people  Hope can help...but advise to wait pros with confirmation...
Congratulations MadhivananFailing to plan is Planning to fail |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-24 : 06:04:01
|
| Hi madhiI didn't try your solution...let you know..anyway thanks...-------------------------R.. |
 |
|
|
Next Page
|