title: use variable in sql trigger creation
body: <p>I'm trying to create a trigger dynamically and need to replace part of the create statement, in particular the database name that a join is done on.</p>
  
  <pre><code>CREATE TRIGGER [dbo].[tr_UseType_update] ON [dbo].[UseType] FOR UPDATE AS
  BEGIN
    SET NOCOUNT ON 
    INSERT [dbo].[UseType]
    SELECT 'Updated', i.*
      FROM inserted
     INNER JOIN [(SELECT DB_NAME())].[dbo].[UseType] i ON inserted.[UseTypeID] = i.[UseTypeID]
  END
  </code></pre>
  
  <p>I've tried this but obviously it just uses the text it doesn't actually evaluate SELECT DB_NAME(), is there a way to get it to evaluate this value.</p>
  
  <p>I'm using sql 2005/8. We have a deployment tool that uses sqlcmd so a fallback will be to change the tool to take in variables that can be passed to sqlcmd but if I can reduce the amount of work and do it in the script itself (which is generated) that would be handy.</p>