Reputation: 436
I have a table called StencilStorage
and it has fields that look like this.
What I am trying to accomplish is creating a stored procedure that will update the table and set PCB_ID
equal to some irrelevant number wherever the next available slot is, sorting the table from low->high by UNIQID
. I have the following so far. The next available slot is labeled as 0
as shown in row 5 in the table above.
CREATE PROCEDURE sp_insert_to_storage
(
@PCB_ID integer
)
AS
BEGIN
UPDATE Tooling.StencilStorage
SET PCB_ID = @PCB_ID
WHERE
GO;
Any help is very much appreciated.
Upvotes: 0
Views: 75
Reputation: 36
CREATE PROCEDURE sp_insert_to_storage
(
@PCB_ID integer
)
AS
BEGIN
UPDATE Tooling.StencilStorage
SET PCB_ID = @PCB_ID
WHERE UNIQID = (SELECT TOP 1 UNIQID FROM Tooling.StencilStorage WHERE PCB_ID = 0 ORDER BY UNIQID)
GO;
Upvotes: 2