Question

I have dates in database.

2013-12-28 00:00:00.000
2013-12-28 00:00:00.000

I wrote a stored procedure for matching Datetime.Now and my database rows.

My stored procedure

Alter PROCEDURE SP_MATCH_DATE
   (
     getdate() ( Year-Month-Day)
   )
AS
BEGIN  
   SELECT *
   FROM MY_TABLE WITH (NOLOCK)
   WHERE 
      Dates = getdate() and Dates > getdate() 
END

I want to set @DATETIME_NOW from getdate(). After that I want to match getdate() to Dates (Year-Month-Day) and getdate() > Dates

Thanks.

Was it helpful?

Solution

Hard to tell what you are asking, did you mean:

WHERE
    Dates >= cast(getdate() as Date)

Casting to datatype Date removes the time portion (be aware that casting on the date column will probably rule the use of any appropriate index. Unless the table is very large, it should not be an issue, as you are performing a select * anyway)

[Also, please note: Dates is not a good name for a column.]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top