I’m working a query that will retrieve various personal information, including first and last names. I want to change the order that the data is returned by based on a passed parameter, called @p_Code. When @p_Code is 4, I want to order by first name, then last name. If it’s not 4, then I want to order by last name, then first name.
I’m working with MS Sql.
Here’s the query as it stands:
Select Last,
First,
Phone,
Email
From Master.dbo.Cust
Order by
case @p_Code
when '4' then
([First], [Last])
else
([Last], [First])
end
This should do it: