USE [Agri]
GO
/****** Object: StoredProcedure [dbo].[in_dm] Script Date: 09/14/2013 11:16:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[idm]
(@Product varchar(15),@Date DateTime ,@BillNo varchar(30) ,
@CustomerName varchar(50),@Address varchar(50) ,
@BrandName varchar(50) ,@Quantity varchar(20),
@ProductPrice varchar(20) , @Requiredno varchar(50),
@Price varchar(50), @Extra varchar(20) ,
@Vat varchar(50),@TotalAmount varchar(50),
@CorrectPrice varchar(50),@type varchar(10)
)
AS
BEGIN
insert into sampl (ProductName,Date,BillNo,CustomerName,Address,BrandName,
Quantity,ProductPrice,Requiredno,Price,Vat,TotalAmount,type)
values(@Product,@Date,@BillNo ,@CustomerName ,@Address ,@BrandName ,
@Quantity ,@ProductPrice ,@Requiredno ,@Price ,@Vat ,@TotalAmount,@type);
insert into samle (ProductName,Date,BillNo,CustomerName,Address,BrandName,
Quantity,ProductPrice,Requiredno,Price,Extra,Vat,CorrectPrice,type) values
(@Product ,@Date,@BillNo ,@CustomerName ,@Address ,@BrandName ,@Quantity ,
@ProductPrice ,@Requiredno ,@Price ,@Extra ,
@Vat,@CorrectPrice,@type );
END
if @type='s'
begin
update pr set purno=purno-Requiredno where BrandName=@BrandName
end
===================================================================
need to update the table pr reduce the requiredno from purno (but requiredno is not inn the table pr) the required no is in the table sampl and samle .


venkata kumarRank #5,034 · 314 reputationPosted Sep 14, 2013, 12:50 AM EDT
try fallowing
declare @purno int
set @purno=(select purno from samp where brandname=@brandname)
declare @Reqno int
set @reqno=(select requiredno from samp where brandname=@brandname)
update pr set purno=@purno-@Reqno where BrandName=@BrandName
selvi subramanianRank #2,007 · 723 reputationPosted Sep 14, 2013, 3:04 AM EDT
venkata kumarRank #5,034 · 314 reputationPosted Sep 15, 2013, 9:05 PM EDT
give mee proper details
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 15, 2013, 10:57 PM EDT
hi,
In SQL,
null + 50 = null
i think you have same problem...
try
update pr set purno= isnull(purno,0)-isnull(Requiredno,0) where BrandName=@BrandName
hope this will help you.
selvi subramanianRank #2,007 · 723 reputationPosted Sep 16, 2013, 1:47 AM EDT
next table
pr table
procedure is above . need to reduce from the pr table if inserted in sampl,samle.
in pr table purno is 100. in sampl,samle the required no is 50. i need in or table (100-50=50)
venkata kumarRank #5,034 · 314 reputationPosted Sep 16, 2013, 2:12 AM EDT
try this
declare @purno int
set @purno=(select purno from pr where brandname=@brandname)
declare @Reqno int
set @reqno=(select requiredno from samp where brandname=@brandname)
update pr set purno=@purno-@Reqno where BrandName=@BrandName
selvi subramanianRank #2,007 · 723 reputationPosted Sep 19, 2013, 11:14 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 19, 2013, 11:37 PM EDT
I think, problem with these two line
declare @purno int
set @purno=(select purno from samp where brandname=@brandname)
declare @Reqno int
set @reqno=(select requiredno from samp where brandname=@brandname)
Instead of this try
declare @purno int
Select @purno = purno from samp where brandname=@brandname
declare @Reqno int
select @Reqno =requiredno from samp where brandname=@brandname
hope this will help you.
venkata kumarRank #5,034 · 314 reputationPosted Sep 21, 2013, 4:00 AM EDT
try the fallowing
declare @purno int
set @purno=(select top 1 purno from pr where brandname=@brandname)
declare @Reqno int
set @reqno=(select top 1 requiredno from samp where brandname=@brandname)