Is it possible?

  • Is there a way to run

    EXEC ('Select * INTO #INS From INSERTED') in trigger?

    OR

    Is there a way to execute this query?

    Declare @columns varchar(200)

    SET @columns= 'stID, stName, stAddress'

    Select @columns INTO #INS From INSERTED

    Regards,

    Shahbaz

  • Is there a way to run

    EXEC ('Select * INTO #INS From INSERTED') in trigger?

    I think SELECT INTO command not allowed within a trigger.

    karthik

  • SELECT * INTO #INS FROM INSERTED

    it works fine.

    I just want to run this query via EXEC command.

  • Could you explain a bit more what you're trying to achieve here please?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • shahbaz_awan (7/31/2008)


    SELECT * INTO #INS FROM INSERTED

    it works fine.

    I just want to run this query via EXEC command.

    You can do it, but the scoping rules around Temp Tables means that the temp table will only exist for the duration of the EXEC and won't be visible in the trigger or anywhere outside of that.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • As you know that INSERTED and DELETED tables do not retrieve the values of text, ntext and image types, and I want to make a generic procedure to create one trigger on all tables, so there are some tables with text, ntext and image data type, I want to exclude these columns by assigning them in a variables so that I can run my query. it fit with permanent tables but with INSERTED or DELETED tables it is not working.

    I have other way to exlcude the tables with text,ntext and image data types and create triggers individually for these tables,

    But plz let me know if there is any way.

    Regards,

    Shahbaz

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply