i have create this if record does not exist of entered item code then procedure should return 0-what ever issue quantity
but when ever no record found it just gives me 0 from execute scalar what should i go to get desired output
ALTER PROCEDURE [dbo].[chkissue]
@item_code numeric(6,0),
@MIN_No varchar(9),
@sr_no numeric(9,0) ,
@issue_qty numeric(9,3)
AS
BEGIN
if exists (select * from tblClosingStock where [item_code] = @item_code)
SELECT closing_qty-@issue_qty from dbo.tblClosingStock where item_code=@item_code
else
return(0-@issue_qty)
END
and
public decimal checkissue(string query,string MINNO,string srno, string item_code,string issue_qty)
{
try
{
connection();
cmd = new SqlCommand(query, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@MIN_No",MINNO);
cmd.Parameters.AddWithValue("@sr_no",srno);
cmd.Parameters.AddWithValue("@issue_qty",issue_qty);
cmd.Parameters.AddWithValue("@item_code", item_code);
Decimal count = Convert.ToDecimal(cmd.ExecuteScalar());
return count;
}
catch (Exception)
{
throw;
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}