I have this table
in which I have template ('T-') StockCodes and FG StockCodes. They would look like 'T-2D7024-13' and '2D7024-13ABC' but ABC could be anywhere from 2-6 alpha characters. Given the template StockCode ('T-'), I want to grab a specific row (specifically the Workcentre='QC' row and use that to insert a row for each FG StockCode. I have the code to grab all of the information that I need, but am not sure how I can go about the insert process without using a cursor and I would really like to get a handle on how to do something like this without using cursors. The code that I have thus far is:
as an example for 'T-2D7024-13' I have these FG StockCodes with the corresponding Operation numbers
So, I would insert the data from 'T-2D7024-13' into dbo.BomOperations replacing 'T-2D7024-13' with '2D7024-13ADB' and replacing the Operation line with '5', leaving everything else just as it was pulled for 'T-2D7024-13'. Does that make sense? It seems like it should be easy, I am just missing some connection in my head, so any help you could give me would be greatly appreciated.
Thanks,
wb
Code:
SELECT [StockCode]
,[Route]
,[Operation]
,[WorkCentre]
,[WcRateInd]
,[WhatIfWcInd]
,[SubcontractFlag]
,[ISetUpTime]
,[IRunTime]
,[IStartupTime]
,[ITeardownTime]
,[IWaitTime]
,[IStartupQty]
,[IMachine]
,[IUnitCapacity]
,[IMaxWorkOpertrs]
,[IMaxProdUnits]
,[ITimeTaken]
,[IQuantity]
,[SubSupplier]
,[SubPoStockCode]
,[SubQtyPer]
,[SubOrderUom]
,[SubOpUnitValue]
,[SubWhatIfValue]
,[SubPlanner]
,[SubBuyer]
,[SubLeadTime]
,[SubDockToStock]
,[SubOffsiteDays]
,[Milestone]
,[ElapsedTime]
,[MovementTime]
,[NarrationCode]
,[AutoNarrCode]
,[NumOfPieces]
,[InspectionFlag]
,[OperYieldPct]
,[OperYieldQty]
,[MinorSetup]
,[MinorSetupCode]
,[ToolSet]
,[ToolSetQty]
,[ToolConsumption]
,[TimeCalcFlag]
,[TimeStamp]
,[Version]
,[Release]
,[TransferQtyOrPct]
,[TransferQtyPct]
,[CoProductCostVal]
,[ResourceMask]
,[MaxOpDelay]
,[IRunTimeEnt]
,[ITimeTakenEnt]
,[IStartupQtyEnt]
,[IQuantityEnt]
,[OperYieldQtyEnt]
,[TransferQtyPctEnt]
,[MaxOpSpan]
,[OpSlack]
,[AllowOpSplit]
FROM [table].[dbo].[BomOperations]
in which I have template ('T-') StockCodes and FG StockCodes. They would look like 'T-2D7024-13' and '2D7024-13ABC' but ABC could be anywhere from 2-6 alpha characters. Given the template StockCode ('T-'), I want to grab a specific row (specifically the Workcentre='QC' row and use that to insert a row for each FG StockCode. I have the code to grab all of the information that I need, but am not sure how I can go about the insert process without using a cursor and I would really like to get a handle on how to do something like this without using cursors. The code that I have thus far is:
Code:
use EncoreCompanyK
Declare @TStockCode varchar(50)
Declare @Length int
Declare @StockCode varchar(20)
SET @TStockCode = 'T-2D7024-13'
SET @StockCode = RIGHT(@TStockCode,len(@TStockCode)-2)
SELECT @Length=(LEN(StockCode)-2)
FROM [EncoreCompanyK].[dbo].[BomOperations]
where StockCode=@TStockCode
and WorkCentre='QC'
select StockCode,MAX(Operation) Operation,MAX(Operation)+1 as 'Next Operation'
from dbo.BomOperations bo
WHERE LEFT(StockCode,@Length) = @StockCode
group by StockCode
order by StockCode, Operation
as an example for 'T-2D7024-13' I have these FG StockCodes with the corresponding Operation numbers
Code:
2D7024-13ADB 4 5
2D7024-13AKL 4 5
2D7024-13AMD 4 5
2D7024-13AMV 4 5
2D7024-13AMVCAL 4 5
2D7024-13AQE 4 5
2D7024-13BL 4 5
2D7024-13CSU 4 5
2D7024-13CYK 4 5
2D7024-13JN 4 5
So, I would insert the data from 'T-2D7024-13' into dbo.BomOperations replacing 'T-2D7024-13' with '2D7024-13ADB' and replacing the Operation line with '5', leaving everything else just as it was pulled for 'T-2D7024-13'. Does that make sense? It seems like it should be easy, I am just missing some connection in my head, so any help you could give me would be greatly appreciated.
Thanks,
wb