Bob
Bob

Reputation: 477

How to view script of executed dynamic TSQL query

I created a stored procedure using dynamic SQL and a cursor a while ago. For upkeeping and adjusting purposes, I'm starting to think that standard SQL would be better than having to adjust the cursor. However, to assess this option, I really don't want to go through rewritting all this logic.

Is there a way to see what queries my cursor creates? I realize there is SQL Profiler (which I used very little), however, after a quick search, I saw that it'll simply display "exec my_stored_procedure" instead of showing the entire script.

Are there any ideas?

My SQL Server version: Microsoft SQL Server 2017 (RTM-CU22) (KB4577467) - 14.0.3356.20 (X64) Aug 20 2020 22:33:27 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)

Thank you

Upvotes: 0

Views: 376

Answers (1)

WAMLeslie
WAMLeslie

Reputation: 1261

If your dynamic SQL is built in a variable before being executed, you could just use a PRINT statement to see what the queries are, like PRINT @SQL. Then it would show in your Messages window in SSMS.

Upvotes: 2

Related Questions