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 |
|
vishu_av
Yak Posting Veteran
69 Posts |
Posted - 2007-06-01 : 08:40:03
|
| Hi All..I am trying to parameterize a tablename in a StoredProcedure something like below and use the below code in my other Stored procedure..CREATE PROCEDURE SP_BACKUPTABLE @TABLENAME VARCHAR(255)ASDECLARE @BACKUPTABLE VARCHAR(255)DECLARE @ALIASTABLE VARCHAR(255)SET @BACKUPTABLE = @TABLENAME + '_BK'SET @ALIASTABLE = @TABLENAME + '_ALIAS'SELECT @ALIASTABLE.* FROM @TABLENAME AS @ALIASTABLEi get error 'near .'...How do i achieve the above code-functionalityThanks in advance |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2007-06-01 : 08:45:25
|
| You'll have to use dynamic sql to achieve this - i.e. construct a SQL string and then execute it. Lookup "Dynamic SQL" in BOL for the specifics.Mark |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-01 : 08:57:49
|
| If you need to really send table name as parameter, use dynamic sql as suggestedRefer www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|