Link to home
Create AccountLog in
Avatar of webressurs
webressursFlag for Norway

asked on

SQL filter by date

I need to make stored procedure that lists all records where 'SentDate' is one specific date (don't care about the time of day). For example, I need to get all record where SentDate is January 4th 2011. The query does not return anything, even if there is alot of records with SentDate this day.

Hope someone please can help me!

PS: How is the correct input format for January 4th 2011? Shoud @SentDate be "01-04-2011"?
Alter PROCEDURE spMessageLog
(
	@TypeId int,
	@Price int,
	@SentDate varchar(100)
)
AS
BEGIN

SET NOCOUNT ON;

SELECT SMS_Out_Log.Optional2 AS TypeId, tblType.Type, SMS_Out_Log.SentDate
FROM SMS_Out_Log INNER JOIN
tblType ON SMS_Out_Log.Optional2 = tblType.Id
WHERE (SMS_Out_Log.Optional2 = @TypeId) AND (SMS_Out_Log.PriceGroup = @Price) AND (SMS_Out_Log.SentDate = CONVERT (varchar, @SentDate, 101))

END
GO

Open in new window

Avatar of jerrypd
jerrypd
Flag of United States of America image

you need to convert the sentdate to the same format as the one you are compaing against...
ASKER CERTIFIED SOLUTION
Avatar of robasta
robasta
Flag of Zimbabwe image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of webressurs

ASKER

This Where statement works:

WHERE    (CONVERT (CHAR(10), SMS_Out_Log.SentDate, 110) = @SentDate)


Thank you :)