Solved

proc that runs any sql

Posted on 2002-06-05
2
293 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

617 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