Update trigger condition, please help me...

SPWGUT 121 Reputation points
2022-04-15T09:28:44.59+00:00

Hello,team.
If I want to update columns, when my number of SP_SW is less than 30, add SP_SW as 50, how can I go about implementing it, please help me, it's urgent for me....
Thanks.
My code:CREATE TRIGGER trigger
ON SP_SW
AFTER INSERT
AS
update SP_SW
set SP_SW=id
from inserted
where inserted.id=id

Azure SQL Database
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,344 questions
Developer technologies | Transact-SQL
0 comments No comments
{count} votes

Accepted answer
  1. LiHong-MSFT 10,056 Reputation points
    2022-04-15T09:53:37.287+00:00

    Hi @SPWGUT
    How about this:

    update SP_SW  
    set SP_SW=case when SP_SW <30 then 50 else id end  
    from inserted  
    where inserted.id=id  
    

    Best regards,
    LiHong


1 additional answer

Sort by: Most helpful
  1. SPWGUT 121 Reputation points
    2022-04-15T09:47:34.52+00:00

    Can it be written like this where inserted.id=id and SP_SW<30,Help me...

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.