From the classic ‘CASE’ construction to the newer PIVOT and ROW_NUMBER() OVER (ORDER BY) functions.
Some methods presented here can have a severe negative impact on performance. Especially the in-line function with a cursor should be used with the utmost precaution.Check the query plan and the statistics i/o (see this post) of your queries before putting the code into your production environment!
1. use a CASE statement
2. use the COALESCE function
3. use ROW_NUMBER() OVER (ORDER BY)
4. Use an inline function
5. Use a pivot