| Author |
Topic |
|
baburk
Posting Yak Master
108 Posts |
Posted - 2008-12-17 : 06:23:26
|
| Hi,This is my query.SET @Query = 'SELECT City1.Station FROM City1 WHERE City1.Sequence' + CAST ( @SequenceName AS VARCHAR ) +' BETWEEN ' + @SeqStart + ' AND ' + @SeqEndEXEC (@Query)How can I able to reverse the Station.Not is asc or desc.I want to reverse the resultsetThanks in advance. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-17 : 06:27:28
|
SET @Query = 'SELECT Station FROM dbo.City1 WHERE Sequence' + @SequenceName +' BETWEEN ' + @SeqStart + ' AND ' + @SeqEnd + ' ORDER BY Station DESC' E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 06:28:20
|
| [code]SET @Query = 'SELECT REVERSE(City1.Station) FROM City1 WHERE City1.Sequence' + CAST ( @SequenceName AS VARCHAR ) +' BETWEEN ' + @SeqStart + ' AND ' + @SeqEndEXEC (@Query)[/code] |
 |
|
|
darkdusky
Aged Yak Warrior
591 Posts |
Posted - 2008-12-17 : 06:29:08
|
| Can you re-write your question? I'm not sure what you mean. |
 |
|
|
baburk
Posting Yak Master
108 Posts |
Posted - 2008-12-17 : 06:45:30
|
quote: Originally posted by darkdusky Can you re-write your question? I'm not sure what you mean.
If my result set isStation-------SalemErodeCoimbatoreEgmoreI want it asStation-------EgmoreCoimbatoreErodeSalemReversing the total result set.ie. UPSIDE DOWN MY RESULT SETThanks for the reply. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 06:46:27
|
| do you have primary key field in your table? may be an identity column? |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-17 : 07:02:17
|
| select identity (int,1,1) as id , name into #temptable from urtable select * from #temptable order by id desc |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 07:08:53
|
quote: Originally posted by bklr select identity (int,1,1) as id , name into #temptable from urtable select * from #temptable order by id desc
you can never guarantee the order in which records get populated in temp table using select... into and hence id wont necessarily be generated in same order in which the records appear in resultset.see thishttp://support.microsoft.com/kb/273586 |
 |
|
|
baburk
Posting Yak Master
108 Posts |
Posted - 2008-12-17 : 07:11:34
|
quote: Originally posted by bklr select identity (int,1,1) as id , name into #temptable from urtable select * from #temptable order by id desc
I have already have 3 temp tables. I don't want to have another temp table. How can I. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 07:14:27
|
quote: Originally posted by baburk
quote: Originally posted by bklr select identity (int,1,1) as id , name into #temptable from urtable select * from #temptable order by id desc
I have already have 3 temp tables. I don't want to have another temp table. How can I.
then whats your primary key/id column? |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-17 : 07:17:22
|
quote: Originally posted by visakh16
quote: Originally posted by baburk
quote: Originally posted by bklr select identity (int,1,1) as id , name into #temptable from urtable select * from #temptable order by id desc
I have already have 3 temp tables. I don't want to have another temp table. How can I.
then whats your primary key/id column?
if u have any primary key or identity column then order by primarykey or identity columnr u have to insert an identity column in ur temp tables then order by that column |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 07:20:46
|
quote: Originally posted by bklrif u have any primary key or identity column then order by primarykey or identity columnr u have to insert an identity column in ur temp tables then order by that column 
didnt understand why you quoted me. or were you suggesting to me? |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-17 : 07:29:00
|
quote: Originally posted by visakh16
quote: Originally posted by bklrif u have any primary key or identity column then order by primarykey or identity columnr u have to insert an identity column in ur temp tables then order by that column 
didnt understand why you quoted me. or were you suggesting to me? 
iam not quote to u visakhi am just explain to baburk |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 07:31:48
|
k |
 |
|
|
|