I have a user defined type as below:
CREATE TYPE [Integer_udt] AS TABLE (
[Id] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC));
Then I have populated it from a query:
DECLARE @Ids [Integer_udt]
INSERT INTO @Ids
SELECT table1.Id
FROM table1
Next, I need pass individual parameters to a stored procedure which accepts a single Id:
EXEC prc_complicated_calculation @Id
Assuming I can’t change prc_complicated_calculation. What is the best way to call it?
My first answer would be dynamic SQL for simple logic and lines of code.
You can also do this with a loop, but I think it’s more work for little gain (unless you are allergic to dynamic SQL).