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 |
|
ddasilva99
Starting Member
26 Posts |
Posted - 2006-10-12 : 11:11:15
|
| Im trying to create a stored procedure where the "FROM" clause is dynamic. I want the FROM clause to be whatever table is passed in from a parameter. For some reason my code doesnt like a parameter in the FROM clause. How do I get this to work? For example:ALTER PROCEDURE d6661a03.AuthenticateStudent @userName VARCHAR(50),@tableName VARCHAR(50)AS SELECT id, name, enabled, password FROM @tableName Where username = @userName |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-10-12 : 11:16:09
|
| exec ('SELECT id, name, enabled, passwordFROM ' + @tableName + 'Where username = ''' + @userName + '''')Not a good idea though.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
ddasilva99
Starting Member
26 Posts |
Posted - 2006-10-12 : 13:22:23
|
| Why isnt this a good idea? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|