New answers tagged

0

Thanks Alex I was able to use what you had written to make a query that will do what I want. This should let me implement my own preprocessor logic. if(1 = 1) BEGIN DECLARE @Query NVARCHAR( MAX ) SET @Query = ( SELECT text /*, query_plan*/ FROM sys.dm_exec_requests AS er CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) AS et ...


0

I added a few minor tweaks as suggested by the community but no one said what I was doing was wrong. I have updated the my github project and will do future enhancements there. Thanks everyone that provided some feedback! Github project link


4

There is no way that a query can output its own text, that I am aware of, but you can certainly capture it using sys.dm_exec_requests. You can try this: -- Query to Run SELECT 100 / 10 -- Query Text Capture DECLARE @Query NVARCHAR( MAX ) SET @Query = ( SELECT text /*, query_plan*/ FROM sys.dm_exec_requests AS er CROSS APPLY ...


0

I'm wondering if you can use the undocumented stored proc sp_MSforeachtable rather than use cursors? Here's a little bit of code that brings back the number of rows in each table. Can you modify it to do what you need to do? use pubs2014 go create table #rowcount (tablename varchar(128), rowcnt int) exec sp_MSforeachtable 'insert into #rowcount select ...


0

I'm short on time so I wasn't able review your code, but I'm basing this answer off your question: How to get the deleted values/capturing changes? Just yesterday I was reading from CH. 8 of Itzik Ben-Gan's "Microsoft SQL Server 2012 T-SQL Fundamentals" and he had a good section on creating audit tables with the use of the OUTPUT clause. To me this was eye ...



Top 50 recent answers are included