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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help

Author  Topic 

shubhada
Posting Yak Master

117 Posts

Posted - 2007-03-27 : 03:04:27
I have one table as follow

PlanName Category Name
Payment Discount ABC
Payment Discount XYZ
Payment variance 123
Payment variance 345
Contract General PQR
Contract General MNO
Contract General JKL
Contract General HIS

I want to shift the HIS record after 345 record.

My result should be

PlanName Category Name
Payment Discount ABC
Payment Discount XYZ
Payment variance 123
Payment variance 345
Contract General HIS
Contract General PQR
Contract General MNO
Contract General JKL

Please tell me how I can shift the data

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-27 : 03:08:22
Use ORDER BY

SELECT * FROM Table1
ORDER BY PlanName DESC, Category, CASE WHEN Name = 'HIS' THEN 0 ELSE 1 END, Name DESC


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

shubhada
Posting Yak Master

117 Posts

Posted - 2007-03-27 : 03:16:56
i want to save the shifted data into table.
How I can update the table

SQLTeam
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-27 : 03:18:59
The order of records in a relational database has no meaning! Only when presenting the data, the order can have meaning.
Why is this so important to you?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

shubhada
Posting Yak Master

117 Posts

Posted - 2007-03-27 : 03:19:57
also i don't want to change the existing order of Name.

SQLTeam
Go to Top of Page
   

- Advertisement -