Re: Trigger For DateTime
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Tue, 19 Jul 2005 21:29:46 +0000 (UTC)
(wackyphill@xxxxxxxxx) writes:
> Can someone give me a simple example of how to force a datetime value
> to be stripped of the time portion when it is added/updated to a table.
> I intend to use it for date only.
>
> I figured a trigger was the way to do this but haven't gotten the
> syntax right. Can someone please show me how? I've never written a
> trigger before.
CREATE TRIGGER tbl_tri ON tbl FOR INSERT, UPDATE AS
UPDATE tbl
SET datecol = convert(char(8), t.datecol, 112)
FROM tbl t
JOIN inserted i ON t.keycol1 = i.keycol1
AND t.keycol2 = i.keycol2
...
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
.
- Follow-Ups:
- Re: Trigger For DateTime
- From: wackyphill
- Re: Trigger For DateTime
- References:
- Trigger For DateTime
- From: wackyphill
- Trigger For DateTime
- Prev by Date: Re: Time Out Problem
- Next by Date: Re: easily editting fields with more than 1024 characters
- Previous by thread: Re: Trigger For DateTime
- Next by thread: Re: Trigger For DateTime
- Index(es):
Relevant Pages
|