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
 How can I insert today's year (2014) into this SQL

Author  Topic 

d247
Starting Member

6 Posts

Posted - 2014-04-06 : 19:10:15
Hi everyone,
I have the following working correctly as a trigger, however, I want to change one of the values (2016) to calculate the current year's value.. so in 2017, it would put 2017.

Can anyone tell me the SQL command to do so?

CREATE TRIGGER TRG_NEW_EQUIPMENT
ON ATHLETE AFTER INSERT
AS
BEGIN
INSERT INTO Equipment (Equipment_ID, Equipment_Model, Equipment_Year, Equipment_Brand, Equipment_Color, Equipment_Condition_Rating)
VALUES ('150','Big Spin','2016','K2','Blue','5')
END;
GO

d247
Starting Member

6 Posts

Posted - 2014-04-06 : 19:12:15
In SQL Server
Go to Top of Page

d247
Starting Member

6 Posts

Posted - 2014-04-06 : 19:18:12
Nevermind - I got it!!!

CREATE TRIGGER TRG_NEW_EQUIPMENT
ON ATHLETE AFTER INSERT
AS
BEGIN
INSERT INTO Equipment (Equipment_ID, Equipment_Model, Equipment_Year, Equipment_Brand, Equipment_Color, Equipment_Condition_Rating)
VALUES ('150','Big Spin',(Year(GETDATE())),'K2','Blue','5')
END;
GO
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-04-07 : 09:10:21
You can also use datepart(year,GETDATE())

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -