How would I write a query that subtracts 1 from a value?Our parts carry a sequence number that keeps them arranged in our work orders.Here's a sample table:Serial_Number WorkOrder_Number WorkOrder_Qty WorkOrder_SeqC710125 1005 456201 250 158C710125 1006 456201 250 159C710125 1007 456201 250 160C710125 1008 456201 250 161C710125 1009 456201 250 162C710125 1010 456201 250 163C710125 1011 456201 250 164
If a part number (i.e. Serial_Number 'C710125 1007') gets started and is later removed (postpone the job or the part was damaged in production), we set it's sequence number to 0 (no longer part of the sequence). To keep the books straight, we need to take all sequence numbers greater than this and drop them down one.The sample table should now look like this:Serial_Number WorkOrder_Number WorkOrder_Qty WorkOrder_SeqC710125 1005 456201 250 158C710125 1006 456201 250 159C710125 1007 456201 250 0C710125 1008 456201 250 160C710125 1009 456201 250 161C710125 1010 456201 250 162C710125 1011 456201 250 163
How would I write a query to reduce certain sequence numbers by one?Here's my lame attempt at a start:UPDATE ACP_PartsSET WorkOrder_Seq=(SELECT WorkOrder_Seq FROM ACP_Parts WHERE (WorkOrder_Number=@WorkOrder_Number) AND (/* What could I write here? */) ) - 1WHERE (WorkOrder_Number=@WorkOrder_Number) AND (WorkOrder_Seq > @WorkOrder_Seq)
Any help is certainly appreciated.
Avoid Sears Home Improvement