I have a table like
city | pincode
abcd | 123456
xyz | 326545
asd | 625844
city | 999999
and I want the result sorted with the selected pincode
first
If I select pincode
is 625844
which city is asd
it must be show first
Desired output:
city | pincode
asd | 625844 <<-- this is selected pincode must be first
abcd | 123456
xyz | 326545
city | 999999
select * from tbl
order by (case when pincode = '625844' then 0 else 1 end), pincode
or if the selected pincode is being passed in as a parameter @pincode, this should work
select * from tbl
order by (case when pincode = @pincode then 0 else 1 end), pincode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With