How could I query in a table with any of its fields? something more or less like this:
declare @variable varchar(50)
set @variable = 'Proveedor'
select * from proveedor where @variable like '%va%'
Although I had that idea, but it does not filter.
You can build the query as a string and then run it with sp
sp_executesql
:Whenever dynamic sql is executed, it must be well tied that we cannot allow sql injection, because if we directly allow the client to supply information directly to the engine through text, we are exposed.
Assuming you already have this part solved.
The scenario you pose with various columns of various types.
One of the parameters to take into account is the type of column you are going to query, and depending on the type, deliver the query with apostrophes, or without them, or with an equal, or with a like. At your discretion according to the information to obtain.
For this, it is possible to query the Information_schema system view about the type of columns in our table and mount the dynamic query with this result.
If you look at the query, first the column type is searched and depending on the type that corresponds to the suppliers table, the where is established. If the column is varchar the filter is like '%xx%' where xx is supplied by a variable, but if the column is decimal the filter will be = xx
If I search for another column, for example nums and I pass a decimal value
exec sp_executeSql