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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored Procedure using column names - help please

Author  Topic 

legacyvbc
Starting Member

37 Posts

Posted - 2007-08-23 : 12:04:52
Ok, I cannot figure this out but it can't be that hard. I must be missing something.
I am trying to create a stored procedure that updates a specific cell in a table according to the column heading and the index number. The problem is that I would like the column heading to be a parameter.
To better explain here is a basic example of what I am trying to do:

Table looks like this
Date, Car, House
8/23/2007, 25, 200
8/1/2007, 20, 300
7/15/2007, 22, 250

I would like a sp that will take two parameters @column_name and @date and will return the value of that particular cell:

select @column_name from tblTable where date=@date

I'm sure I am missing something and this is a very basic example but I have spent way too much time trying to figure this out and need help.

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 12:26:20
http://www.sommarskog.se/dynamic_sql.html



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

legacyvbc
Starting Member

37 Posts

Posted - 2007-08-23 : 12:55:33
brilliant! Thank you so much for the help. I feel like I searched everywhere with no luck.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-23 : 12:56:16
And then you come to SQLTeam!



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -