Solved

proc that runs any sql

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
best counters for cpu high usage 3 28
MS SQL with ODBC 5 35
SQL Server Count where two id types exist in column 8 27
always on switch back after failover 2 32
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

785 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