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.
| Author |
Topic |
|
js.reddy
Yak Posting Veteran
80 Posts |
Posted - 2008-01-10 : 01:25:44
|
| I have a table called MysamppleI want to create a stored procedure to display a particular column of the table.Here, I want to give column name as the parameter of the stored procedure.Is it possible! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-10 : 01:34:02
|
| You might need dynamic sql for thisCREATE PROC GetColumncolumnname varchar(100)ASDECLARE @Sql varchar(8000)SELECT @Sql='SELECT ' + @columnname + ' FROM Table'EXEC (@Sql)GOCan i ask why you want to do it this way? |
 |
|
|
js.reddy
Yak Posting Veteran
80 Posts |
Posted - 2008-01-10 : 02:08:05
|
Thank you visakh quote: Originally posted by visakh16 You might need dynamic sql for thisCREATE PROC GetColumncolumnname varchar(100)ASDECLARE @Sql varchar(8000)SELECT @Sql='SELECT ' + @columnname + ' FROM Table'EXEC (@Sql)GOCan i ask why you want to do it this way?
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-10 : 03:27:02
|
| You should avoid passing object names as parameterMake sure you read this fullywww.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|