• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1013
  • Last Modified:

Sql Query stored as a string in a table

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
2 Solutions
HuaMinChenBusiness AnalystCommented:
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.
Dale BurrellDirectorCommented:
declare @Sql nvarchar(max)

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

Split_PinAuthor Commented:
Thanks both were helpful responses - apologies for my slow reply I was unable to access network for several days,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now