| |

VerySource

 Forgot password?
 Register
Search
View: 941|Reply: 7

May I ask a trigger

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-7 09:30:01
| Show all posts |Read mode
I wrote a trigger as follows, when jlzt like 1111% of resume table, update other fields
In other cases, the update situation is different, but the check syntax is correct, but there is a problem at runtime, help me see.

CREATE TRIGGER [upjlzttojl] ON [dbo]. [Resume]
FOR UPDATE
AS
begin
   if update (jlzt)
   begin
      declare @jlzt varchar (15)
      select @ jlzt = jlzt from updated
      if @jlzt like '1111111111%'
update resume set zjl = 3 from updated where reid = updated.reid
      else if @jlzt like '1111%'
update resume set zjl = 2 from updated where reid = updated.reid
      else if @jlzt like '0000000000%'
update resume set zjl = 0 from updated where reid = updated.reid
      else
update resume set zjl = 1 from updated where reid = updated.reid
   end
   if update (ejlzt)
   begin
      declare @ejlzt varchar (15)
      select @ ejlzt = ejlzt from updated
      if @ejlzt like '1111111111%'
update resume set ejl = 3 from updated where reid = updated.reid
      else if @ejlzt like '1111%'
update resume set ejl = 2 from updated where reid = updated.reid
      else if @ejlzt like '0000000000%'
update resume set ejl = 0 from updated where reid = updated.reid
      else
update resume set ejl = 1 from updated where reid = updated.reid
   end
end
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-3-27 16:30:01
| Show all posts
begin
   declare @jlzt varchar (15)
     set @ jlzt = jlzt
      select @jlzt from updated
      if @jlzt like '1111111111%'
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-3-27 18:00:01
| Show all posts
CREATE TRIGGER [upjlzttojl] ON [dbo]. [Resume]
FOR UPDATE
AS
begin
   if update (jlzt)

   begin
      declare @jlzt varchar (15)

      if (select count (1) from updated where jlzt like '1111111111%')> 0
update resume set zjl = 3 from updated where reid = updated.reid
      else if (select count (1) from updated where jlzt like '1111%')> 0
update resume set zjl = 2 from updated where reid = updated.reid
      else if (select count (1) from updated where jlzt like '0000000000%')> 0
update resume set zjl = 0 from updated where reid = updated.reid
      else
update resume set zjl = 1 from updated where reid = updated.reid
   end
   if update (ejlzt)
   begin
      declare @ejlzt varchar (15)
      select @ ejlzt = ejlzt from updated where ejlzt like '1111111111%'
      if (select count (1) from updated where ejlzt like '1111111111%')> 0
update resume set ejl = 3 from updated where reid = updated.reid
      else if (select count (1) from updated where ejlzt like '1111%')> 0
update resume set ejl = 2 from updated where reid = updated.reid
      else if (select count (1) from updated where ejlzt like '0000000000%')> 0
update resume set ejl = 0 from updated where reid = updated.reid
      else
update resume set ejl = 1 from updated where reid = updated.reid
   end
end
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-3-27 19:45:01
| Show all posts
begin
   declare @jlzt varchar (15)
     set @ jlzt = jlzt
      declare @str nvarchar (1000)
      set @ str = 'select' + @ jlzt + 'from updated'
      exec (@str)
      if @jlzt like '1111111111%'
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-3-31 15:15:01
| Show all posts
Still not working, halo
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-4-2 23:15:01
| Show all posts
I just saw that there is an updated table. Only inserted and deleted.
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-4-3 10:45:01
| Show all posts
CREATE TRIGGER [upjlzttojl] ON [dbo]. [Resume]
FOR UPDATE
AS
begin
   if update (jlzt)
   begin
      if (select count (1) from inserted where jlzt like '1111111111%')> 0
update resume set zjl = 3 from inserted where reid = inserted.reid
      else if (select count (1) from inserted where jlzt like '1111%')> 0
update resume set zjl = 2 from inserted where reid = inserted.reid
      else if (select count (1) from inserted where jlzt like '0000000000%')> 0
update resume set zjl = 0 from inserted where reid = inserted.reid
      else
update resume set zjl = 1 from inserted where reid = inserted.reid
   end
   if update (ejlzt)
   begin
      if (select count (1) from inserted where ejlzt like '1111111111%')> 0
update resume set ejl = 3 from inserted where reid = inserted.reid
      else if (select count (1) from inserted where ejlzt like '1111%')> 0
update resume set ejl = 2 from inserted where reid = inserted.reid
      else if (select count (1) from inserted where ejlzt like '0000000000%')> 0
update resume set ejl = 0 from inserted where reid = inserted.reid
      else
update resume set ejl = 1 from inserted where reid = inserted.reid
   end
end
Reply

Use magic Report

0

Threads

40

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-4-30 15:15:02
| Show all posts
cv4bf5d65fd
 
 
   
I just saw that there is no updated table, only inserted and deleted.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list