I'm creating a stored procedure in SQL server and want to achieve the following:
I have to look up all the ResourceID's (could be any number of resources) for a certain ClientID in the Resources table. Then I have to insert a row in the Planning table for each ResourceID found.
So I'll have something like
WHILE EXISTS (SELECT ResourceID AS @ResourceID FROM Resources WHERE ClientID = @ClientID)
BEGIN
INSERT INTO Planning (ResourceID, Date)
VALUES (@ResourceID, @Date)
NEXT
END
I have already found that using a cursor might be the way, but that doesn't lead me to anything usable