I have searched the internet and saw many examples for more than 2 weeks but i could not reach to a solution. I am not an Sql Server expert, thats why it is difficult to me to interpret the codes i saw.
Here is my thing:
I have a table named "sqlQueries" which contains two columns: clientID, theQuery. In "theQuery" there is an sql query starts with "select clientID from clients...".
As you can see, there is another table named "clients" which contains my clients' data.
I need a function with two parameters: @query, @clientID
The function must "execute" the query that comes with the "@query" parameter where i learned that "sql_executesql" can be used. This is what i couldnt handle.
I just want my function "return" 0 (zero) or 1 which will depend on the result of executed query. If the result of the query is null than will return 0. But if the query is not null than we will look at that: Is the "clientID" comes with second parameter (@clientID) in the result set of executed query. If yes than 1 else 0.
For example: Result of the executed query is: 15, 25, 35, 40 and my clientID comes with @clientID is 38. The result of function will be 0.
Result of the executed query is: 15, 25, 35, 38 and my clientID comes with @clientID is 38. The result of function will be 1.
Thanks anyway. Best wishes.