0

I have a function which name is fnc_FiderSumOfAboneSayisi that can be sent an integer value with parameter @prm_fiderid. so I have a table which name is fider_data that has ID column. Now I want to in order to send fider_data ID column value as parameter to my fnc_FiderSumOfAboneSayisi function as a loop.

how can i do that ??

----------FUNCTION

alter function fnc_FiderSumOfAboneSayisi @prm_fiderid as int

returns int

as

begin

declare @parent int = @prm_fiderid;

declare @SUM int;

with q As(

select * from fider_data    where ParentId = @parent

union all

select lc.*    from q

join fider_data lc on lc.ParentId = q.ID )

SELECT @SUM=(SELECT sum(SAYI) FROM q where ID<33000) return @SUM

end

----------TABLE fider_data

ADI ID

TM 1 1

TM 2 2

TM 3 3

TM 4 4

TM 5 5

TM 6 6

TM 7 7

TM 8 8

TM 9 9

.

.

.

1 Answer 1

0
DECLARE @id INT

SET @id = (SELECT TOP 1.ID FROM fider_data ORDER BY ID ASC)



WHILE @id IS NOT NULL

BEGIN
    SELECT  fnc_FiderSumOfAboneSayisi @prm_fiderid = @id

    SET @id = (SELECT TOP 1.ID FROM fider_data WHERE ID > @id ORDER BY ID ASC)  

END
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.