Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update using trigger with data in the database

Author  Topic 

Kyle Doouss
Yak Posting Veteran

64 Posts

Posted - 2011-06-24 : 10:29:39
I have written the following trigger. I am trying to insert the data from the address ID 1 (the customer main address) if the inserted contact does not have anying in the address.

The trigger works if you just put a text insert like 'Text' but as soon as I try and put in a field from the system I think it treats it as the field you are inserting which is obviously blank. How do a get it to take date from the account you are inserting on

create TRIGGER [dbo].[Udef_new_customer1]
ON [dbo].[SL_Addresses]
for INSERT
AS
BEGIN
SET NOCOUNT ON;

update [SL_Addresses]
set
[AD_ADDRESS] = SL_Addresses.ad_address
FROM SL_ADDRESSES INNER JOIN inserted ON SL_ADDRESSES.SL_AD_PRIMARY = inserted.SL_AD_PRIMARY
WHERE ISNULL(inserted.AD_ADDRESS,'') = ''

END


GO

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-06-24 : 15:30:34
Looking at the query, that behavior seems to be what one would expect. From what I can tell, you are asking to update the ad_address column in the table SL_Addresses with the ad_address column from the same table AND same row.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-06-25 : 14:05:46
How do a get it to take date from the account you are inserting on

does that mean you're trying to insert system date? then use function GETDATE()

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -