Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Make a SQL Query parameterize at run time with dynamic columns and values like an IN Clause()

$
0
0

I need to use parameterized queries, but the problem the column and values are dynamic.

It might be 5 columns with column 1: 10 values ; column 2: 20 values ; column 3: 1 value ; column 4: 9 values ; column 5 100 values.

     DashboardSqlDataSource dataSource = (DashboardSqlDataSource)dashboard.DataSources[0];
            CustomSqlQuery salesPersonQuery = (CustomSqlQuery)dataSource.Queries[0];
            salesPersonQuery.Parameters.Add(new QueryParameter("startDate", typeof(Expression), 
                new Expression("[Parameters.yearParameter] + '/01/01'")));
            salesPersonQuery.Parameters.Add(new QueryParameter("endDate", typeof(Expression), 
                new Expression("[Parameters.yearParameter] + '/12/31'")));
            salesPersonQuery.Sql = "select * from SalesPerson where OrderDate between @startDate and @endDate";

Above is what the code might look like.

Would after the WHERE need to be an IN clause? What is the best and most efficient way to do this?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>