| Author |
Topic |
|
arulss
Starting Member
4 Posts |
Posted - 2007-04-04 : 06:07:49
|
| I am having a table like thisID111222I want the result table likeID121212How to write the query? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-04 : 06:10:34
|
| Is this the ONLY column in the table?Peter LarssonHelsingborg, Sweden |
 |
|
|
arulss
Starting Member
4 Posts |
Posted - 2007-04-04 : 06:12:31
|
| No i have some other columns also but the order should be like this. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-04 : 06:14:22
|
| [code]-- Prepare sample dataDECLARE @Sample TABLE (ID INT)INSERT @SampleSELECT 1 UNION ALLSELECT 1 UNION ALLSELECT 1 UNION ALLSELECT 2 UNION ALLSELECT 2 UNION ALLSELECT 2-- Stage the dataDECLARE @Stage TABLE (RecID INT IDENTITY(0, 1), ID INT)INSERT @StageSELECT IDFROM @SampleORDER BY ID-- Show the expected outputSELECT IDFROM @StageORDER BY RecID % 3, ID[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-04 : 06:19:22
|
| In the staging part, you should add an extra row for ORDER BY, to ensure that all 1's and all 2's are sorted correct internally.Peter LarssonHelsingborg, Sweden |
 |
|
|
arulss
Starting Member
4 Posts |
Posted - 2007-04-04 : 06:20:26
|
| Could u please explain it.Since the table which i have mentioned is a temp table written in a stored procedure. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-04 : 06:45:20
|
create your temp table with an identity column as what Peter has shown above. KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-04-04 : 09:14:46
|
quote: Originally posted by arulss I am having a table like thisID111222I want the result table likeID121212How to write the query?
Can you give me practical example on when you are required to do this type of sorting?MadhivananFailing to plan is Planning to fail |
 |
|
|
arulss
Starting Member
4 Posts |
Posted - 2007-04-05 : 01:41:42
|
| In the stored procedure i have created a temp table and stored some values from another table. I have to display the records which is in the temp table in the above order. It contains a column name called RecordOrder. |
 |
|
|
|