Home Forums SQL Server 7,2000 T-SQL Using Variables as column names in select statement RE: Using Variables as column names in select statement

  • Hello Theo,

    as far as I know it isn't possible, and even if it was, I don't think it would be advisable. A trigger calling SP also isn't the best solution, trigger should contain short pieces of code that can be executed quickly, because triggers tend to be fired pretty often. Dynamic SQL in a trigger is something I wouldn't recommend.

    Also, I would be VERY careful with triggers, especially if you are updating another database. If a trigger fails, everything will be rolled back... if I understand it correctly, it means that as soon as the other database is offline for any reason, or is experiencing blocking problems etc., you won't be able to do anything in your database (that is, not on tables with such triggers).

    You didn't describe in detail what is the reason for setting up the triggers. Maybe replication, or some other way would accomplish what you need? If you really want to use triggers, the best way out seems to be to use the trigger to insert just the ID of changed row into some "ToDo" table and then use a job that will update the rows in another database (based on current values in your DB) and delete ID from the ToDo table.