I need to select all records from a table that were insered this year (not previous years).. here is what i have:
DECLARE @CurrentDateTime datetime
set @CurrentDateTime = getDate()
PRINT @CurrentDateTime
DECLARE @GetRecordYear varchar(4)
set @GetRecordYear = datepart(yy, @CurrentDateTime)
PRINT datepart(yy, @CurrentDateTime)
print @GetRecordYear
Select * from tblA
where dtDate < = @CurrentDateTime
where ( datepart(yy, @CurrentDateTime) = @GetRecordYear )
For some reason this is not working..
If i do this:
if (datepart(yy, @CurrentDateTime) = @GetRecordYear )
print 'true'
else
print 'false'
this returns true - so i am not sure what i am doing wrong in my above query...
Any suggestions?
Thanks,
-Bell
DECLARE @CurrentDateTime datetime
set @CurrentDateTime = getDate()
PRINT @CurrentDateTime
DECLARE @GetRecordYear varchar(4)
set @GetRecordYear = datepart(yy, @CurrentDateTime)
PRINT datepart(yy, @CurrentDateTime)
print @GetRecordYear
Select * from tblA
where dtDate < = @CurrentDateTime
where ( datepart(yy, @CurrentDateTime) = @GetRecordYear )
For some reason this is not working..
If i do this:
if (datepart(yy, @CurrentDateTime) = @GetRecordYear )
print 'true'
else
print 'false'
this returns true - so i am not sure what i am doing wrong in my above query...
Any suggestions?
Thanks,
-Bell