Nick Juelich
Nick Juelich

Reputation: 436

Query to update row value in next blank column

I have a table called StencilStorage and it has fields that look like this.

enter image description here

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

Answers (1)

sleeveroller
sleeveroller

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

Related Questions