Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Need to create a procedure or query dynamically.
dynamic table name from a dropdown ,and the same for fields.

how to choose a datatype of input parameter they can vary from nvarchar,int,date or any valid datatype depands upon the selected field name from the dropdown.


SQL
create procedure field_search(@name nvarchar(255),@field1_name nvarchar(255),@field1_value nvarchar(255),@field2_name nvarchar(255),@field2_value nvarchar(255))
as begin
SELECT * from @name
WHERE     (@field1_name LIKE '%@field1_value%') AND (@field2_name LIKE '%field2_value%')
end


thanks in advance..!!!
Posted
Updated 21-Mar-12 3:11am
v2
Comments
Nelek 21-Mar-12 9:12am    
Tags added

1 solution

Use sql_variant datatype, it can hold most of the SQL datatypes except for the ones like 'text'. You can then use SQL_Variant_Property function to the actual datatype of the variable
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900