Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Anushka
Yak Posting Veteran
79 Posts |
Posted - 2008-06-20 : 03:51:25
|
| Currentlotorderqty,Orginallotquantity are there in InventorySerialNumbersBoth Currentlotorderqty,Orginallotquantity will be equal initiallyAvailableQty,AllottedQty field are there in TrnDetGreySourcePlanThis AvailableQty field = CurrentlotorderqtyIf we allot in frontend that allotedqty will be inserted in TrnDetGreySourcePlan and that quantity will be deducted in currentlotquantity(up to here i had done)Now comming to deletion i have to add the alloted qty to currentlotqty in InventorySerialNumbersFOR EX :If i execute this i will get 5 recordsThese are the select td.*,isn.* from TrnDetGreySourcePlan td,InventorySerialNumbers isnwhere td.companyid=isn.companyidand td.divisionid =isn.divisionidand td.departmentid=isn.departmentidand td.BaseLineno= isn.OrderLineNumberand td.BaseOrderno=isn.OrderNumberand td.[FPS/TFSno]=isn.PurchaseOrderNumberand td.Batchno = isn.SerialNumberHere as iam having multiple rows for one orderno:when that orderno is deleted each and every row should be updatedjust to get brief idea....the sp is:DECLARE @AllottedQty intSELECT @AllottedQty =AllottedQty FROM TrnDetGreySourcePlanwhere CompanyID= @CompanyIDand DivisionID=@DivisionIDand DepartmentID=@DepartmentIDAND ORDERNo =@OrderNumberDECLARE @Currentlotorderqty intselect @Currentlotorderqty = Currentlotorderqty + @AllottedQty from InventorySerialNumbersUpdate InventorySerialNumbersSETCurrentlotorderqty= @CurrentlotorderqtyWHERE CompanyID=@CompanyIDAND DivisionID=@DivisionIDAND DepartmentID=@DepartmentIDAND ORDERNo =@OrderNumberi have to update each and every row of that order ...The table structureInitially after inserting Batchno,available,alloted,orginallotorderqty,currentlotorderqty, orderno2 100 30 100 70 10013 100 10 100 90 10014 100 20 100 80 1001after deleting i need the sp for which only orderno passedBatchno,available,alloted,orginallotorderqty,currentlotorderqty, orderno2 100 0 100 70+30 10013 100 0 100 90+10 10014 100 0 100 80+20 1001 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-20 : 05:00:47
|
May be this:-Update iset i.currentlotorderqty=i.currentlotorderqty+i.available, i.available=0FROM InventorySerialNumbers iinner join (select td.*,isn.* from TrnDetGreySourcePlan td,InventorySerialNumbers isnwhere td.companyid=isn.companyidand td.divisionid =isn.divisionidand td.departmentid=isn.departmentidand td.BaseLineno= isn.OrderLineNumberand td.BaseOrderno=isn.OrderNumberand td.[FPS/TFSno]=isn.PurchaseOrderNumberand td.Batchno = isn.SerialNumber)ton t.OrderNumber=i.ORDERNo |
 |
|
|
Anushka
Yak Posting Veteran
79 Posts |
Posted - 2008-06-20 : 05:03:19
|
| Only Batchno PRIMARYKEY HERE ,NOT ORDERNO. |
 |
|
|
Anushka
Yak Posting Veteran
79 Posts |
Posted - 2008-06-20 : 05:11:59
|
| error:The column 'CompanyID' was specified multiple times for 't'.Hi visakha...when i had executed Update iset i.currentlotorderqty=i.currentlotorderqty+i.available, i.available=0FROM InventorySerialNumbers iinner join (select td.*,isn.* from TrnDetGreySourcePlan td,InventorySerialNumbers isnwhere td.companyid=isn.companyidand td.divisionid =isn.divisionidand td.departmentid=isn.departmentidand td.BaseLineno= isn.OrderLineNumberand td.BaseOrderno=isn.OrderNumberand td.[FPS/TFSno]=isn.PurchaseOrderNumberand td.Batchno = isn.SerialNumber)ton t.Baseorderno=i.ORDERNUMBER |
 |
|
|
Anushka
Yak Posting Veteran
79 Posts |
Posted - 2008-06-20 : 05:15:48
|
| The available field is in TrnDetGreySourcePlan but here it was taken InventorySerialNumbers set i.currentlotorderqty=i.currentlotorderqty+i.available, |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-20 : 05:25:45
|
quote: Originally posted by Anushka The available field is in TrnDetGreySourcePlan but here it was taken InventorySerialNumbers set i.currentlotorderqty=i.currentlotorderqty+i.available,
then change it accordingly also instead of using * use actual column names inside the subqueryUpdate iset i.currentlotorderqty=i.currentlotorderqty+t.available,i.available=0FROM InventorySerialNumbers iinner join (select td.*,isn.* from TrnDetGreySourcePlan td,InventorySerialNumbers isnwhere td.companyid=isn.companyidand td.divisionid =isn.divisionidand td.departmentid=isn.departmentidand td.BaseLineno= isn.OrderLineNumberand td.BaseOrderno=isn.OrderNumberand td.[FPS/TFSno]=isn.PurchaseOrderNumberand td.Batchno = isn.SerialNumber)ton t.Baseorderno=i.ORDERNUMBER |
 |
|
|
Anushka
Yak Posting Veteran
79 Posts |
Posted - 2008-06-20 : 05:35:30
|
| it is showing The column 'CompanyID' was specified multiple times for 't'. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-20 : 05:45:23
|
quote: Originally posted by Anushka it is showing The column 'CompanyID' was specified multiple times for 't'.
did you replace * with the columns you wanted? i had specifically told you to do that in last post. this error is because you have Company ID coming from both the tables. I didnt replace them as i dont know your column names. |
 |
|
|
Anushka
Yak Posting Veteran
79 Posts |
Posted - 2008-06-20 : 06:01:45
|
| same error :(i wroteUpdate iset i.currentlotorderqty=i.currentlotorderqty+t.allottedQtyFROM InventorySerialNumbers iinner join (select isn.PurchaseOrderNumber,isn.currentlotorderqty,isn.SerialNumber,td.allottedqty,td.companyid,td.divisionid,td.departmentid,td.BaseLineno,td.BaseOrderno,td.[FPS/TFSno],td.Batchno,isn.companyid,isn.divisionid,isn.departmentid,isn.OrderLineNumber,isn.OrderNumber from TrnDetGreySourcePlan td,InventorySerialNumbers isnwhere td.companyid=isn.companyidand td.divisionid =isn.divisionidand td.departmentid=isn.departmentidand td.BaseLineno= isn.OrderLineNumberand td.BaseOrderno=isn.OrderNumberand td.[FPS/TFSno]=isn.PurchaseOrderNumberand td.Batchno = isn.SerialNumber)ton t.ORDERNUMBER=i.ORDERNUMBER |
 |
|
|
Anushka
Yak Posting Veteran
79 Posts |
Posted - 2008-06-20 : 06:05:37
|
| The currentlotorderqty in InventorySerialNumbers should be add up to allottedQty which is there in TrnDetGreySourcePlaneven after writing column names:it is showing The column 'CompanyID' was specified multiple times for 't'. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-20 : 06:28:59
|
quote: Originally posted by Anushka The currentlotorderqty in InventorySerialNumbers should be add up to allottedQty which is there in TrnDetGreySourcePlaneven after writing column names:it is showing The column 'CompanyID' was specified multiple times for 't'.
you have it specified mulitple times! please remove one of themUpdate iset i.currentlotorderqty=i.currentlotorderqty+t.allottedQtyFROM InventorySerialNumbers iinner join (select isn.PurchaseOrderNumber,isn.currentlotorderqty,isn.SerialNumber,td.allottedqty,td.companyid,td.divisionid,td.departmentid,td.BaseLineno,td.BaseOrderno,td.[FPS/TFSno],td.Batchno,isn.companyid,isn.divisionid,isn.departmentid,isn.OrderLineNumber,isn.OrderNumber from TrnDetGreySourcePlan td,InventorySerialNumbers isnwhere td.companyid=isn.companyidand td.divisionid =isn.divisionidand td.departmentid=isn.departmentidand td.BaseLineno= isn.OrderLineNumberand td.BaseOrderno=isn.OrderNumberand td.[FPS/TFSno]=isn.PurchaseOrderNumberand td.Batchno = isn.SerialNumber)ton t.ORDERNUMBER=i.ORDERNUMBER |
 |
|
|
Anushka
Yak Posting Veteran
79 Posts |
Posted - 2008-06-20 : 11:40:20
|
| Hi,Thanx for ur reply some extent iam getting by writing like this but ............hi actually serial number brings the records which were alloted ,if not all the records will be updated for which the qty is not alloted but having orderno (passing parameter)actually i.serialnumber = t.SerialNumber(which is the only primary key...I think cursor is req to impliment this......as only orderno iam passing from front endALTER PROCEDURE [dbo].[UpdateSerialNumber] --'pangea','default','default','2010' @CompanyID NVARCHAR(36), @DivisionID NVARCHAR(36), @DepartmentID NVARCHAR(36), @OrderNumber NVARCHAR(36) ASBEGINUpdate iset i.currentlotorderqty=i.currentlotorderqty+t.allottedQtyFROM InventorySerialNumbers iinner join (select isn.PurchaseOrderNumber,isn.originallotorderqty ,isn.currentlotorderqty,isn.SerialNumber,td.allottedqty,td.BaseLineno,td.BaseOrderno,td.[FPS/TFSno],td.Batchno,isn.OrderLineNumber,isn.OrderNumber from TrnDetGreySourcePlan td,InventorySerialNumbers isnwhere td.companyid=isn.companyidand td.divisionid =isn.divisionidand td.departmentid=isn.departmentidand td.BaseLineno= isn.OrderLineNumberand td.BaseOrderno=isn.OrderNumberand td.[FPS/TFSno]=isn.PurchaseOrderNumberand td.Batchno = isn.SerialNumberand isn.currentlotorderqty ! = isn.originallotorderqty and td.orderno =@OrderNumber)ton t.ORDERNUMBER=i.ORDERNUMBER END |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-20 : 12:49:20
|
quote: Originally posted by Anushka Hi,Thanx for ur reply some extent iam getting by writing like this but ............hi actually serial number brings the records which were alloted ,if not all the records will be updated for which the qty is not alloted but having orderno (passing parameter)actually i.serialnumber = t.SerialNumber(which is the only primary key...I think cursor is req to impliment this......as only orderno iam passing from front endALTER PROCEDURE [dbo].[UpdateSerialNumber] --'pangea','default','default','2010' @CompanyID NVARCHAR(36), @DivisionID NVARCHAR(36), @DepartmentID NVARCHAR(36), @OrderNumber NVARCHAR(36) ASBEGINUpdate iset i.currentlotorderqty=i.currentlotorderqty+t.allottedQtyFROM InventorySerialNumbers iinner join (select isn.PurchaseOrderNumber,isn.originallotorderqty ,isn.currentlotorderqty,isn.SerialNumber,td.allottedqty,td.BaseLineno,td.BaseOrderno,td.[FPS/TFSno],td.Batchno,isn.OrderLineNumber,isn.OrderNumber from TrnDetGreySourcePlan td,InventorySerialNumbers isnwhere td.companyid=isn.companyidand td.divisionid =isn.divisionidand td.departmentid=isn.departmentidand td.BaseLineno= isn.OrderLineNumberand td.BaseOrderno=isn.OrderNumberand td.[FPS/TFSno]=isn.PurchaseOrderNumberand td.Batchno = isn.SerialNumberand isn.currentlotorderqty ! = isn.originallotorderqty and td.orderno =@OrderNumber)ton t.ORDERNUMBER=i.ORDERNUMBER END
Dont you have serialno in any other table by which you can link to this table to perform the update? |
 |
|
|
|
|
|
|
|