Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
1.30/5 (3 votes)
See more:
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

SQL
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
C#
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);
      //    string value = Convert.ToString(cmd.ExecuteScalar());
       //   Decimal  count = Convert.ToDecimal(value);
          Decimal count = Convert.ToDecimal(cmd.ExecuteScalar());
          return count;
      }
      catch (Exception)
      {

          throw;
      }
      finally
      {
          if (con.State == ConnectionState.Open)
          {
              con.Close();
          }
      }
  }
Posted
Comments
Herman<T>.Instance 16-Nov-12 3:32am    
have you tried changing return(0-@issue_qty)
to select (0-@issue_qty)
Member-515487 16-Nov-12 3:46am    
thanks now its working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900