Joseph Marchena
Joseph Marchena

Reputation: 39

How to pass certain values from a table to a stored procedure

This is my problem. I have a table tbl_archivos with values like this:

Id   desc    namerc
---------------------------
1    arch1   RC201721091701
2    arch2   RC201724091701

I have to pass all the values of the column namerc in my table (above) to a stored procedure like parameter.

Like this :

sp_runproceess_billing 'RC201721091701'

and then the another value RC201724091701.

I am not allowed to use a cursor!

Please help me with this issue.

Thank you

Upvotes: 0

Views: 211

Answers (1)

realnumber3012
realnumber3012

Reputation: 1062

try this solution

DECLARE @t AS TABLE(id INT PRIMARY KEY IDENTITY, namerc VARCHAR(50))
    INSERT INTO @t 
    SELECT DISTINCT namerc FROM tbl_archivos
    ORDER BY tbl_archivos
    DECLARE @index INT = 1
    DECLARE @max INT = (SELECT COUNT(*) FROM @t)
    DECLARE @current_namerc VARCHAR(50)
    WHILE @index <= @max
    BEGIN
       SELECT @current_namerc  = namerc FROM @t WHERE id = @index
       EXEC sp_runproceess_billing @current_namerc
       SET @index = @index + 1
    END

Upvotes: 2

Related Questions