Re: SQL trigger.

Re: SQL trigger.

 

  

For the date column, why not just use a defaukt
constraint, e.g.:

ALTER TABLE Profile ADD DEFAULT GETDATE() FOR
Document_Date

For the trigger, I'm guessing you need something like
this:

CREATE TRIGGER trg_iu_Profile ON Profile
FOR INSERT, UPDATE AS
UPDATE p SET DocName = 'Document No. ' +
CONVERT(varchar(24), p.DocNumber)
FROM Profile p JOIN inserted i ON p.DocNumber =
i.DocNumber
WHERE i.DocName = ''

I hope you have a very good reason to have objects
with owner other than dbo...


--- [Email Address Removed] wrote:
> Good day everyone!
>
> I have a problem with a trigger.
>
> I created a trigger to insert the current date into
> a filed if no date as
> been specified. For some reason it does not work.
>
> Here is how it look:
>
> CREATE TRIGGER GETDATE ON docsadm.PROFILE
> FOR INSERT,UPDATE
> AS
>
> UPDATE DOCSADM.PROFILE
> SET DOCNAME = 'Document No.' + ' ' +
> CONVERT(varchar(24), (DOCNUMBER))
> WHERE DOCNAME = ''
>
> DECLARE @MYDATE DATETIME
> DECLARE @MYSTRING VARCHAR(11)
> SELECT @MYSTRING = CONVERT(VARCHAR, GETDATE())
> SELECT @MYDATE = CONVERT(DATETIME, @MYSTRING)
>
> UPDATE DOCSADM.PROFILE
> SET document_date = @MYDATE
> WHERE document_date = 'JAN 1 1753'
>
> Can anyone tell me why it does not work?
> If I place the trigger in it freeze the application.
>
>
>
> Thanks
>
>
>
>
>


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
MS Sql Server LazyDBA home page