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
 General SQL Server Forums
 New to SQL Server Programming
 insert into a table exec sp_executesql @strSql

Author  Topic 

aoriju
Posting Yak Master

156 Posts

Posted - 2012-10-04 : 09:12:17
Hi all,

How to insert a sp_executesql statement
Example:
insert into [dbo].[tbl_ETS_DataHolder]
exec sp_executesql @strSql WITH RECOMPILE;

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-10-04 : 09:23:31
Did you try what you have posted?
Is the result not what you need?
Are there any error messages?


Too old to Rock'n'Roll too young to die.
Go to Top of Page

aoriju
Posting Yak Master

156 Posts

Posted - 2012-10-04 : 09:27:33
not getting any error...but data not inserted
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-10-04 : 09:36:15
is there any output if you run that exec... without insert?


Too old to Rock'n'Roll too young to die.
Go to Top of Page

aoriju
Posting Yak Master

156 Posts

Posted - 2012-10-04 : 09:38:30
yes output is there..do we need any out parameter or ?..then pls provide the syntax
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-10-04 : 09:47:47
On the given information I can say: it should work.
But I can't see what you are really doing.

Is this little test working for you?
declare @sql nvarchar(max)
set @sql = 'select ''Test'''
create table #sample (testcol varchar(255))
insert #sample
exec sp_executesql @sql with recompile

select * from #sample
drop table #sample



Too old to Rock'n'Roll too young to die.
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-04 : 09:48:48
Check these links. You can get idea....

http://www.kodyaz.com/articles/tsql-sp_executesql-with-output-parameters.aspx
http://msdn.microsoft.com/en-us/library/ms188001.aspx


--
Chandu
Go to Top of Page
   

- Advertisement -