Skip to content
Advertisement

how to use dynamic query inside a function

i’m trying to create a function GETUSERPROP(prop, filter_prop, filter_value) that selects one item in database filtering by property and value

the query outside function is running fine, but when I try to put this inside a function, I get the error

I need this as a function to use inside other queries, like this:

Advertisement

Answer

From error message it is obvious we cannot use dynamic sql in function. Dynamic sql is only possible in procedure. So you have to think in alternative. If number of combination is not too much then you can use IF statement for each possible combination for example.

……………. ……………

and so on..

or something like this

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement