Reputation: 1145
I need to use between
in a stored procedure. This is my code
ALTER PROCEDURE sp_tb_sales_entry_total_product_where_date
@to_date varchar(15),
@from_date varchar(15)
AS
BEGIN
SELECT *
FROM tb_sales_entry_total_product
WHERE [Sales Date] BETWEEN @to_date AND @from_date
END
I passed two values 01-01-2014
and 10-01-2014
. In my table also in same format.
Problem is its not selecting values. Where is my error?
Upvotes: 2
Views: 217
Reputation: 713
use sql format..
DATE_FORMAT(colName,\'%d/%m/%Y\') AS colName
you can use the format you want.. link
Upvotes: -1
Reputation: 204766
Switch them
WHERE [Sales Date] BETWEEN @from_date AND @to_date
Upvotes: 4
Reputation: 726579
Operator BETWEEN
in SQL has the following syntax:
test_expression [ NOT ] BETWEEN begin_expression AND end_expression
Since the begin_expression
needs to be first, you have to switch the order of from_date
and to_date
:
SELECT * FROM tb_sales_entry_total_product WHERE [Sales Date] BETWEEN @from_date AND @to_date
Upvotes: 7