Reputation: 61
I have a column of DateTime and I give only the date to a stored procedure and check it against the column in SQL table. But entries in column also contains time with date but I have to compare the only date part of column with the given input. Please reply
alter procedure [dbo].[db]
@date DateTime
As
begin
select * from [dbo].[production_schedule]
where DATEPART('YYYY',date)= DATEPART('YYYY-MM-DD',@date)
end;
EXEC [dbo].[db] '2002-07-01',1,0
I have to give only date in the procedure but I have to select those rows which have the same date in the column date.
Upvotes: 0
Views: 102
Reputation: 10274
Write as:
alter procedure [dbo].[db]
@date DateTime
As
begin
select * from [dbo].[production_schedule]
where convert ( varchar(10), date, 111) = convert (varchar(10),@date,111)
end
Go
-- When there's only one input parameter in the sproc then why have 3 comma separated
-- inputs in exec statement?
EXEC [dbo].[db] '2002-07-01'
Upvotes: 0
Reputation: 1867
Try this
select * from [dbo].[production_schedule]
where convert(date,date)= convert(date,@date)
Upvotes: 1