sql server - looking for procedure instead of trigger which we can schedule as a job -
sql server - looking for procedure instead of trigger which we can schedule as a job -
instead of trigger planning write procedure can run using job work same way trigger these 2 tables in same way. how can that?
here tables column names
1.tblcal id(int,not null) uid(varchar(10),null) desc(varchar(200),null) date(datetime,null) avbl(varchar(5),null) 2.tblevent id(int,notnull) uid(varchar(10),null) desc(varchar(200),null) date(datetime,null)
down trigger on tblevent..
alter trigger [dbo].[tru] on [dbo].[tblevent] insert declare @cuid char(6), @cudesc char(40), @cudate datetime set nocount on select @cuid = i.uid , @cudesc=i.desc, @cudate=i.date inserted if(@cudesc !='available') begin update tblcal set avbl='out', desc=@curdesc cadate=@cudate , uid=@cuid end set nocount off
i have problem desc column.desc going in , out need update tblcal differently different descriptions;in case don't think trigger reliable;means illustration 10 desc need update in , other 10 need update out
actually every th on tblevent info loaded 1 time loaded fired trigger , update in tblcal.
but client looking procedure can schedule job after tblevent entry done on thursday.
how can stored procedure?
procedure create procedure dbo.usp_updateeventdata begin set nocount on; update c set c.avbl = 'out' ,c.[desc] = e.[desc] [dbo].tblcal c inner bring together [dbo].[tblevent] e on c.[uid] = e.[uid] , c.cadate = e.[date] --<-- check if want e.[desc] <> 'available' -- bring together on date not datetime end -- cast both columns date
also if keeping trigger need modify trigger definition handle multiple inserts, can utilize same logic in procedure update trigger definition.
trigger fixalter trigger [dbo].[tru] on [dbo].[tblevent] insert begin set nocount on; update c set c.avbl = 'out' ,c.[desc] = i.[desc] [dbo].tblcal c inner bring together inserted on c.[uid] = i.[uid] , c.cadate = i.[date] i.[desc] <> 'available' end
sql-server database triggers
Comments
Post a Comment