Performing a year comparison within SQL Server - TechRepublic
Question
June 19, 2007 at 08:43 AM
dcleary

Performing a year comparison within SQL Server

by dcleary . Updated 19 years, 1 month ago

Hello

I’m trying to do a comparison of a full date field to a year field using:

min(SUBSTRING(CONVERT(CHAR,ISNULL(me.e_start,GETDATE()),110),7,4)) “Start_Year”

to convert the date field in to a year, I then want to compare this converted field to a current year view that I have created.

e.g 19/06/2007 will convert to 2007

me.start=(SELECT AC_YR from current_ac_yr)

basically I want to know everybody who’s e_start date falls in to the current year 2007

When I run it i keep getting error:

Conversion failed when converting datetime from character string.

Can I actually do a comparison like this?

Can anybody help?

This discussion is locked

All Comments