Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sql Query stored as a string in a table

Posted on 2014-01-01
3
Medium Priority
?
988 Views
Last Modified: 2014-01-05
Hi experts,
Joping this is a straight-forward and well worn path...

Basically I wish to store a number of different SQL queries in a table (as individual strings). Then I hope to be able to call a specific query from the table and execute it.

How would I go about executing a query which is stored as a string in a field on a particular table? Appreciate any tutorials etc that you can point me to. I will be working in Microsoft Sql Server 2008.

Cheers, split_pin
0
Comment
Question by:Split_Pin
[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
3 Comments
 
LVL 11

Assisted Solution

by:HuaMinChen
HuaMinChen earned 1000 total points
ID: 39750803
The way is to use Dynamic sql to call the query that is stored in the table.

You can also use a cursor to retrieve the stored column in the table.
0
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 1000 total points
ID: 39750838
declare @Sql nvarchar(max)

select @Sql = MySqlString from MyTable where id = @Id

execute(@Sql)
0
 

Author Closing Comment

by:Split_Pin
ID: 39757980
Thanks both were helpful responses - apologies for my slow reply I was unable to access network for several days,
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

610 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