title: Using Select case on trigger sql server
body: <p>I have stuck on this trigger when I use to select case from the inserted table, the result was NULL.</p>
  
  <pre><code> TRIGGER trgInsertPenjDetail ON [dbo].[TbDtlOutBrgGd1] 
   AFTER INSERT
  
   AS
  
  BEGIN
      DECLARE @namaProduct varchar (255)
      DECLARE @jenisProduct varchar (50)
      SET @jenisProduct = (select jenis from Inserted) 
  
      SELECT @namaProduct =
          CASE @jenisProduct
                      WHEN 'PAKET'
                                 THEN (SELECT tb.nm AS namaProduct from dbo.TbHdPaket AS tb
                  INNER JOIN Inserted AS i ON tb.id = i.brg)
                      WHEN 'TERAPI'
                                 THEN (SELECT tb.nm AS namaProduct from dbo.TbMterapi AS tb
                  INNER JOIN Inserted AS i ON tb.id = i.brg)
              WHEN 'BARANG'
                                 THEN (SELECT tb.nama AS namaProduct from dbo.TbMstBb AS tb
                  INNER JOIN Inserted AS i ON tb.id = i.brg)
                      ELSE '-'
                  END
  
  
      BEGIN
          UPDATE b
          SET b.rek = b.rek + '( ' + convert(varchar(5),i.qty) + ' ' + @namaProduct+' ' + i.ket+ ' )'
          FROM dbo.TbRek AS b
          INNER JOIN Inserted AS i ON b.nott = i.nott
      END
      BEGIN
          UPDATE b
          SET    b.rek = replace(b.rek, ')(', '+')
          FROM dbo.TbRek AS b
          INNER JOIN Inserted AS i ON b.nott = i.nott
      END
  END
  </code></pre>
  
  <p>What is the right syntax for CASE or IF on this trigger? Thanks.</p>