Reputation: 3307
I am trying to check in a stored procedure a date in table if it is equal to Today's date.
Code is
DECLARE @p0 datetime
Set @p0 =GETDATE()
Select * from testtable
where dateCol=@p0
This doesn't work it just gives empty rows. How can I accomplish that? Thanks
Upvotes: 1
Views: 1677
Reputation: 34784
If dateCol is just the date, not DATETIME, you can use:
SELECT *
FROM Table
WHERE dateCol = CAST(GETDATE() AS DATE)
Upvotes: 1
Reputation: 70738
You need:
SET @p0 = CONVERT(CHAR(10),GETDATE(),103)
GETDATE()
returns the date and time. You probably have records with todays date but not at this exact time.
Also you don't really need to store it in @p0
. You could use the expression directly in the WHERE
clause.
Upvotes: 0