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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to figure out sql statement before execute

Author  Topic 

gamaz
Posting Yak Master

104 Posts

Posted - 2010-04-28 : 14:13:53
Hi,
I have as a part of a stored procedure a sql statement followed by exec sql statement.





This stored proc. was written by someone who is no longer with the company.

set @sqlCmd = 'insert into #tt_aging
etc.

exec (@sqlCmd)

I need to know the sql statement before executing it with the exec cmd. Is there any way to figure out the sql statement that is being executed prior to execution. I appreciate any help. Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-28 : 14:24:19
PRINT @sqlCmd

Or save it somewhere like in a table:

INSERT INTO SomeLoggingTable (SqlCmd, CmdDate) VALUES(@sqlCmd, GETDATE())

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

gamaz
Posting Yak Master

104 Posts

Posted - 2010-04-28 : 15:19:14
Thanks Tara for the generous help. It worked great.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-28 : 15:20:27
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -