Easy way to convert exec sp_executesql to a normal query?

后端 未结 10 1280
一整个雨季
一整个雨季 2021-01-31 09:37

When dealing with debugging queries using Profiler and SSMS, its pretty common for me to copy a query from Profiler and test them in SSMS. Because I use parameterized sql, my q

10条回答
  •  暖寄归人
    2021-01-31 10:06

    I spent a little time making an simple script that did this for me. It's a WIP, but I stuck a (very ugly) webpage in front of it and it's now hosted here if you want to try it:

    http://execsqlformat.herokuapp.com/

    Sample input:

    exec sp_executesql 
              N'SELECT * FROM AdventureWorks.HumanResources.Employee 
              WHERE ManagerID = @level',
              N'@level tinyint',
              @level = 109;
    

    And the output:

    BEGIN
    DECLARE @level tinyint;
    
    SET @level = 109;
    
    SELECT * FROM AdventureWorks.HumanResources.Employee  
              WHERE ManagerID = @level
    END
    

    The formatting of the actual SQL statement once I've plucked it from the input is done using the API at http://sqlformat.appspot.com

提交回复
热议问题