|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to execute a combined SQL character string in stored procedurecould any one tell me how to execute a combined SQL string in stored procedure, thanks! my code as follow: /*******************************************/ CREATE procedure sp_copy3sectable @tblname varchar(10) as declare @sqlstr varchar(50) set @sqlstr = 'select * into ' + @tblname + ' from tbl_3sec' --my question is : how to execute @sqlstr ? GO /*******************************************/ Joseph Lu wrote:
> declare @sqlstr varchar(50) exec(@sqlstr)> > set @sqlstr = 'select * into ' + @tblname + ' from tbl_3sec' > > --my question is : how to execute @sqlstr ? > Chris Joseph,
as the other poster replied you can use EXEC (@sqlstr) You can also use the stored procedure sp_executesql the sp allows you do to some parameter replacement if you wish. For your example, it really doesn't matter much either way. -- Show quoteWayne Snyder MCDBA, SQL Server MVP Mariner, Charlotte, NC I support the Professional Association for SQL Server ( PASS) and it''s community of SQL Professionals. "Joseph Lu" wrote: > hi all, > could any one tell me how to execute a combined SQL string in stored > procedure, thanks! > > my code as follow: > /*******************************************/ > CREATE procedure sp_copy3sectable > > @tblname varchar(10) > > as > > declare @sqlstr varchar(50) > > set @sqlstr = 'select * into ' + @tblname + ' from tbl_3sec' > > --my question is : how to execute @sqlstr ? > > GO > /*******************************************/ > > > |
|||||||||||||||||||||||