c# - Comparing datetime values in SQL server 2008 -
i'm facing challenge in comparing datetime values in sql server 2008.
i want select rows table 'plane_allocation_table' column 'to_date' of type datetime less today's date , time (which obtained using getdate()). , update 2 tables depending on values above query returns.
however, queries tried don't return rows.
the last stored procedure worte looks :
-- procedure update total_allocation in hanger_details , validity of booking in plane_allocation_details :
create procedure [dbo].[update_total_allocation_apms] declare @now datetime select @now = getdate() update hanger_details set total_allocation = total_allocation - 1 hanger_number in ( select hanger_number plane_allocation_details to_date <= @now , validity = 'valid' ) update plane_allocation_details set validity = 'not valid' to_date <= @now
the comparison of 'to_date' , '@now' isn't working. there solution comparing datetime values table in stored procedure?
ps : please note want make comparison on basis of date time. instance, if time datetime '2014-12-20 10:00:00.000' now, , column value '2014-12-20 09:59:00.000' row must returned.
edit1 : i've corrected typo there. (=< <=)
you can cast datetime
values date
-only values.
e.g.
declare @today date select @today = convert(date, getdate()) update plane_allocation_details set validity = 'not valid' convert(date, to_date) <= @today
Comments
Post a Comment