Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:40:47+00:00 2026-05-31T11:40:47+00:00

I have stuck on this trigger when I use to select case from the

  • 0

I have stuck on this trigger when I use to select case from the inserted table, the result was NULL.

 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

What is the right syntax for CASE or IF on this trigger? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:40:49+00:00Added an answer on May 31, 2026 at 11:40 am

    I would change the top part of the trigger so that the trigger looks like this:

    CREATE TRIGGER trgInsertPenjDetail ON [dbo].[TbDtlOutBrgGd1]  
     AFTER INSERT 
     AS 
    BEGIN 
        BEGIN 
            UPDATE b 
            SET b.rek = b.rek + '( ' + convert(varchar(5),i.qty) + ' ' + 
            CASE i.jenis 
                WHEN 'PAKET'  THEN nama1
                WHEN 'TERAPI' then name2
                WHEN 'BARANG' THEN nama3
                ELSE '-' 
            END + ' ' + i.ket+ ' )' 
            FROM dbo.TbRek AS b 
            INNER JOIN (Select qty, jenis, ket, t1.nm as nama1, t2.nm as nama2, t3.nama as nama3 from Inserted as i
                            LEFT JOIN TbHdPaket as t1 on i.brg = t1.id
                            LEFT JOIN TbMterapi as t2 on i.brg = t2.id
                            LEFT JOIN TbMstBb as t3 on i.brg = t3.id) 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 
    

    This way even with multiple inserts the inserted table should update TbRek with everything that gets updated.

    I assume the bottom part of the query is just to make sure that “)(” gets replaced with a “+”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a noob in jQuery and have stuck at this. I have the following
I have been stuck on this for days, and was wondering if anyone had
I have been stuck on this for a while. i have tried and I
I have been stuck on this and don't really know how to go about
I have been stuck on this silly if statement, whatever i do, I cannot
so i have been stuck with this issue for 3 weeks now and i
I have now been stuck at this for some time so I though to
I have been stuck for a long time on this simple but obtuse message
I've been stuck with this for weeks now and have no idea where I'm
i know this is basic but somehow i have been stuck here for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.