SQL Query in table field

  • hi people.

    is it possible to save a SQL Query into a table field

    and then execute it when a condition arises?

  • 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.

    .

  • 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!

    "Press any key...
    Where the heck is the any key?
    hmmm... Let's see... there's ESC, CTRL, Page Up...
    but no any key"
    - Homer Simpson
  • thanks thats fantastic. exactly what i was looking for...

  • why do u need such a thing ?

    "Keep Trying"

  • 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