Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger criteria 1

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
CA
Hail,

I just started to play with triggers in my SQL database. I got the basics of it down I think but this is what I need to do.
One of my fields is a date+time, with datetime as datatype. I want to trigger each time a record has a datetime for today (so date is today, time is whenever). How would I write the WHERE statement?

I tried:

CREATE TRIGGER GetASAP ON dbo.reservation_tbl
FOR INSERT,UPDATE
AS

insert into ASAP
select cnfrmtn_nmbr, gmt_strt, cnfrnc_nm, lcl_phn, lns_usd, cnfrnc_typ, cncl, tm_stmp from inserted
WHERE cnfrnc_typ like "OPDO" or cnfrnc_typ like "OPMM" or cnfrnc_nm like "*$*" and gmt_strt like "" & date() & "*"

I also tried date without () with no success. Is there a way I can use the date function?

Phailak
 
Hi there,
In SQL you should use like
WHERE ... AND
CONVERT(CHAR(10),myDateColumn,101) = CONVERT(CHAR(10),getDate,101)


Getdate() returns the todays date from the server. And by converting it to char(10) we are making sure that the date part should be matched.

Hope this will help.
 
Hail,

Thanx a lot, I'll check that out right away

Phailak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top