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)
 Newbie "YEAR" question

Author  Topic 

scottpaul4000
Starting Member

4 Posts

Posted - 2007-10-29 : 13:02:55
When I run this it returns data correctly
select *
from toc t inner join td8 d
on t.tocid = d.tocid
where t.parentid = 406623 and YEAR(d.date) = 2005

When I run this:
Begin
Update td8
set td8.year = '2005'
from toc t inner join td8 d
on t.tocid = d.tocid
where t.parentid = 406623 and YEAR(d.date) = 2005

I get the following message:
Server: Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near '2005'.

I'm guessing the year and date fields and year and date functions are causing the problems but I'm just guessing. Anyone got advise for the new guy?

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-10-29 : 13:03:58
Remove the quotes around 2005.You need quotes for strings not numeric values.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

scottpaul4000
Starting Member

4 Posts

Posted - 2007-10-29 : 13:23:46
Actually TD8.Year is a string field. (don't ask why, it's along story)
I tried removing the quotes anyway and got the same results.
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-10-29 : 13:26:10
And what is the datatype for d.date?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

scottpaul4000
Starting Member

4 Posts

Posted - 2007-10-29 : 13:46:41
Datetime
Go to Top of Page

scottpaul4000
Starting Member

4 Posts

Posted - 2007-10-29 : 14:01:47
Here's the problem, I'm an idiot. The first line was supposed to be BEGIN TRAN not Begin. What it was expecting was End.
Thanks for the help though. I appreciate it.
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-10-29 : 15:18:08
ahh..

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -