Solved

proc that runs any sql

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now