October 6, 2008 at 2:17 am
hi people.
is it possible to save a SQL Query into a table field
and then execute it when a condition arises?
October 6, 2008 at 2:25 am
Could you explain what you are trying to achieve?
You could create a TRIGGER on the table and SQL Server will execute the trigger when data is modified (insert/update/delete). Add your code to the trigger that checks for the given condition and execute the desired TSQL statements.
.
October 6, 2008 at 2:56 am
Hi there,
Hope this helps...
First lets create some sample data...
CREATE TABLE SprocTable
(
IDINTIDENTITY,
SprocVARCHAR(MAX)
)
GO
CREATE PROC USP_Hi
AS
SELECT 'Hi'
RETURN
GO
CREATE PROC USP_Hello
AS
SELECT 'Hello'
RETURN
GO
INSERT INTO SprocTable
SELECT 'USP_Hi'
UNION
SELECT 'USP_Hello'
SELECT * FROM SprocTable
like so...
Now lets execute our sproc
DECLARE @sproc VARCHAR(MAX)
SELECT @Sproc=Sproc FROM SprocTable WHERE ID = 1
EXEC @Sproc
Please tell me if this was helpful
_____________________________________________
[font="Comic Sans MS"]Quatrei Quorizawa[/font]
:):D:P;):w00t::cool::hehe:
MABUHAY PHILIPPINES!
October 6, 2008 at 3:18 am
thanks thats fantastic. exactly what i was looking for...
October 6, 2008 at 3:26 am
why do u need such a thing ?
"Keep Trying"
October 8, 2008 at 6:40 am
if your proc is not too large, isn't it faster to make it
DECLARE @strSQL NVARCHAR(MAX)
SELECT @strSQL = kode FROM table
EXECUTE sp_executesql @strSQL
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply