0

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.

  • See the answer here (http://stackoverflow.com/questions/28481189/exec-sp-executesql-with-multiple-parameters) - what you want to do is "run executesql with parameters" – Darren Wainwright May 27 '16 at 12:06
  • I understand u r mad at me :) But please dont. U think that there a lot of answers to this question. But for me, no. I saw maybe hundreds of examples like ur post, i tried hundreds of codes but i could not do it. So, i just want "an expert suggestion" that helps me. I even do not know how to evaluate the result of "executed query" to return 0 or 1. So please, if u r willing to enlighten me i will appriciate ur afforts. Link sharing is not what i need. Please try to understand me. – Serkan Cebeci May 27 '16 at 16:43

1 Answers1

0

Here is the answer: It is not possible to execute an SP inside a function.