Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Get row from settings table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

267 Posts

Posted - 11/14/2012 :  05:10:42  Show Profile  Reply with Quote
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"

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?

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/14/2012 :  06:46:36  Show Profile  Reply with Quote
You can use PIVOT operator. The code would be something like this:
		[Name] IN ([Name1],[Name2],[Name3])
PIVOT (MAX([Value]) FOR [Name] IN ([Name1],[Name2],[Name3]))p
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000