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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 RIGHT Function

Author  Topic 

ivra
Starting Member

18 Posts

Posted - 2009-03-06 : 09:26:03
scenario:

i have applied_date and year column. how can i populate the year column by getting the year value from appled_date column by using this example:

applied_date = 6/3/2004 (mm/dd/yyyy)
year should be 2004

Please help..

Thanks,

Arvi

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-06 : 09:30:42
If your applied date is a varchar or char data type you can use RIGHT.

SELECT RIGHT(applied_date,4).

If not, you need to tell us whats the data type is.
Go to Top of Page

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2009-03-06 : 09:32:23
If it is datetime:
select datepart( year,applied_date)
Go to Top of Page

ivra
Starting Member

18 Posts

Posted - 2009-03-06 : 09:35:25
both columns are nvarchar.

a tried this statement but it doesnt work:

update rolling
set year= (select applied_date,RIGHT(applied_date,4))

Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-06 : 09:48:17
It should be like this...

update rolling
set year= RIGHT(applied_date,4)
Go to Top of Page

ivra
Starting Member

18 Posts

Posted - 2009-03-06 : 09:50:57
thanks guys..it works.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-06 : 10:38:43
Welcome
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-07 : 01:53:52
Why do you store date value in nvarchar column?

Madhivanan

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

- Advertisement -