简单的方法来执行exec sp_executesql到一个正常的查询? [英] Easy way to convert exec sp_executesql to a normal query?

查看:712
本文介绍了简单的方法来执行exec sp_executesql到一个正常的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理使用Profiler和SSMS的查询时,对于我来说,从Profiler复制查询并在SSMS中测试它们是很常见的。因为我使用参数化的sql,所以我的查询都以exec sp_executesql查询的形式发送。

  exec sp_executesql 
N'/ *这里有一些查询* /',
N'@ someParameter tinyint ',
@ someParameter = 2

我会把它转换成正常查询易于编辑(intellisense,错误检查,行号等):

  DECLARE @someParameter tinyint 
SET @someParameter = 2

/ *这里有一些查询* /

查询越大越复杂,难度越大。当你多次来回的时候,这可能是一个痛苦的屁股,并吸收了大量的时间。

有没有一个简单的(例如,宏命令)的方式来将muh executionql转换成更方便的东西?

解决方案

我不知道现有的加载项可以做这个。但是你可以创建一个:)

一些正则表达式和一些字符串连接,然后把它卖给Vinko和其他寻找这个功能的灵魂。



如果您想深入了解这一点,下面是创建SSMS插件的一些信息:
http://sqlblogcasts.com/blogs/jonsayce/archive/2008/01/ 15 / building-a-sql-server-management-studio-addin.aspx


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 queries are all sent as exec sp_executesql queries.

exec sp_executesql 
N'/*some query here*/', 
N'@someParameter tinyint',
@ someParameter =2

I'll take this and convert it into a normal query for ease of editing (intellisense, error checking, line numbers, etc):

DECLARE @someParameter tinyint
SET @someParameter = 2

/*some query here*/

Of course, the bigger and more complex the query, the harder to do this. And when you're going back and forth multiple times, it can be a pain in the ass and soak up lots of time.

Is there an easy (e.g., macro command) way to convert muh executesql into something more convenient?

解决方案

I am not aware of an existing Add-In that can do this. But you could create one :)

A few regular expressions and some string concatenation and after that sell it to Vinko and other souls looking for this functionality.

If you're feeling like diving into this, here is some information on creating an SSMS addin: http://sqlblogcasts.com/blogs/jonsayce/archive/2008/01/15/building-a-sql-server-management-studio-addin.aspx

这篇关于简单的方法来执行exec sp_executesql到一个正常的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆