how to execute a udf in dynamic sql

  • Hi

    i want to execute a function in dynamic sql. is it possible to execute a function in dynamic sql. i tired it but i got a error. please find the below for more clarification

    declare @STR varchar(50),@sql varchar(max)

    select @STR='''1'',''2'',''3'',''4''')

    set @sql='select data from split('+@str+','','')

    execute @sql

    i am getting error as incorrect number of arguments

    can any one please help me on this

    Thanks,

    Rock

  • you are calling it wrong. try: exec(@sql) or preferrably use sp_executesql

    The probability of survival is inversely proportional to the angle of arrival.

  • yeah that is ok. I am getting error on execution of the function in dynamic sql. can u give me a sample Dynamic sql code to execute a function with two parameters

    ex: select * from split(@var,',')

    Thanks in advance

    Regards,

    Rock.

  • Print the @SQL parameter and execute the text manually to debug it - it'll make life much easier

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply