vendredi 29 juillet 2016

How to Toggle between two values from table rows in Sql

I have a table name [NavBar] with these columns:

Id [int]
Name [nvarchar]
DisplayOrder [int]

Sample data:

Id   Name   DisplayOrder
---------------------------
 1   Home        1
 2   Products    2
 3   Contact     3
 4   Career      4

I want to write a query to update DisplayOrder between two rows.

For example Contact = 4, Career = 3

Expected output:

1  Home      1
2  Products  2
3  Contact   4
4  Career    3

How do I perform update operation to toggle between two rows display order ?

Input parameter: Id of one row only

Aucun commentaire:

Enregistrer un commentaire