Question : best way to proceduralize this?

i was going to use a TVP, but I am not writing the @deliverables to a table, i am merely using them to perform a join, and retrieve the dataset.

the given @delivarables are unknown.  maybe one, maybe twenty.... but it will always be no,name,qty


declare @deliverables table (num int,name char(10),qty decimal(18,8))
insert @deliverables values
(1,'ABC',50 ),(2,'DEF',2.52),(3,'GHI',20),(4,'JKL',20),(5,'MNO',20),(6,'PQRS',3);
select ug.tableA
from tableA ug join tableB s on s.idfield = ug.idfield
      join @deliverables d
      on ug.num = d.num
                     and ug.idfield = s.idfield
                     and ug.qty = d.qty


advice?

Answer : best way to proceduralize this?

So trying to explain with your code below:

-- TVP Declaration
declare @deliverables table (num int,name char(10),qty decimal(18,8))

-- Inserting values into your TVP
insert @deliverables values
(1,'ABC',50 ),(2,'DEF',2.52),(3,'GHI',20),(4,'JKL',20),(5,'MNO',20),(6,'PQRS',3);

-- JOIN to your TVP
select ug.tableA
from tableA ug join tableB s on s.idfield = ug.idfield
      join @deliverables d
      on ug.num = d.num
                     and ug.idfield = s.idfield
                     and ug.qty = d.qty

And I believe the place where you are struggling is the INSERT statement and if I am correct you are forming those comma separated values using some other function..
Just pass it out or post it so that I can provide the sample procedure..
Random Solutions  
 
programming4us programming4us