I have a SQL server 2008. The table(Items) structure with data i have is as follows:
ID(int) Name(varchar(50)) Price(money)
1 ArchBook 1200.89
2 Freebie 0.00
3 Board 800.54
The datatypes of these column are in the (). I have a select stored proc that takes price as a parameter
create procedure dbo.GetItemByPrice
@price money
as
begin
if @price = '' OR @price is NULL
set @price = ''
select * from dbo.Items
where @price = '' OR price = @price
end
When i send 0 for price from C# code the result is incorrrect. I used cast in stored proc to convert it to money again after if clause.(How do I convert from a money datatype in SQL server?) But it doesnt seem to work. Any suggestions of how i can take care of compare with 0? If price is empty is return all records. C# Code
cnn.Open();
string amount = "0";
var command = new SqlCommand("GetItemsByPrice", cnn);
command.CommandType = CommandType.StoredProcedure;
var param = new SqlParameter("@price", SqlDbType.Money);
param.Value = Convert.ToDecimal(amount);
command.Parameters.Add(param);
var dataReader = command.ExecuteReader();
while (dataReader.Read())
{
//printing columns
}
dataReader.Close();
command.Dispose();