Solved

proc that runs any sql

Posted on 2002-06-05
2
291 Views
Last Modified: 2012-06-21
How would I write a proc that'll run any sql I send it, i.e. exec run_sql("select * from table where field = 'hello world'")?
0
Comment
Question by:arichexp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7058365
Did you try:
Create Procedure sp_DynamicSQL @SQL varchar(1000)

As

Exec @SQL

Anthony
0
 
LVL 2

Accepted Solution

by:
bronwyn_black earned 100 total points
ID: 7058609
There is already a proc to do this in the master database.

you can call it with :

---
sp_sqlexec 'SELECT * FROM pubs..Authors'
---
Very similar to what acperkins suggested, it looks like this:
---
create procedure sp_sqlexec
    @p1 text
as
exec(@p1)
---
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question