'How can I manipulate an external query to Sql Server?

I have a procedure that I wrote in Sql Server. This procedure masks the data returned by the query that comes before it as a string. E.g :

exec datamasking 'select * from [user]'

I want the following if a query called select * from [user] comes to this database, I want to convert this query into a string and work like this:

exec datamasking 'query'

To give an example over Python, if I want to connect to the database and pull data like this:

import pyodbc

conn = pyodbc.connect(r'connectionstring')

cursor = conn.cursor()

cursor.execute("select * from [user]")

As you can see in the last line, when a query is thrown, I want this query to be declared in the database as follows:

exec datamasking 'select * from [user]'

If I get back together, I want to run the external query to the database with my procedure on the sql side and return the masked data to the user. How can I do that. I hope I was able to explain. I would be very happy if you help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source