Hi, I was wondering about the best way to create a sp for something like this. There is a settings table which looks like this: ID SettingName SettingValue 1 "Name 1" "Value 1" 2 "Name 2" "Value 2" 3 "Name 3" "Value 3" 4 "Name 4" "Value 4" etc.
Now, I want to get one row with the value's of a couple of columns, like:
Value 1 Value 2 Value 4
I know you can do this with multiple selects, but is there a better way?
You can use PIVOT operator. The code would be something like this:
SELECT
[Name1],[Name2],[Name3]
FROM
(
SELECT
[Name],
[Value]
FROM
YourTable
WHERE
[Name] IN ([Name1],[Name2],[Name3])
)s
PIVOT (MAX([Value]) FOR [Name] IN ([Name1],[Name2],[Name3]))p