Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I have a Linq Query that works well but I need to write the SQL Query
Can Anybody help me write it?
How can i write the this where and select part in sql command?

VB
ret = new List<RData>();

ret1 = (from a in View
        where
            a.LastRefreshTime>=Filter.From && a.LastRefreshTime<=Filter.To && a.ModelCode == mdlCode &&
            Filter.PN.Select(epn => epn.Substring(0, 11)).Contains(a.H) &&
            Filter.PN.Select(epn => epn.Substring(14, 2)).Contains(a.HV)

        select new RData
        {
            v = a.v,
            Date = a.LastRefreshTime,
            UserId = a.UserId,
            M = a.Name,
        }).Distinct().AsQueryable();
ret = ret1.Where(nr =>
    Filter.M == null || !Filter.M.Any() || Filter.M.Contains(nr.M)
).ToList();
Posted
Comments
Sinisa Hajnal 30-Oct-15 17:05pm    
What have you tried? SQL is not really complicated and SQL has substring function so you can literally transcribe linq into query.
Philippe Mori 30-Oct-15 18:29pm    
LinqPad allows to easily see SQL...

1 solution

You are the only one who has access to the data table you want to query, so it is difficult for anyone else to just translate LINQ to SQL with no chance to try it out.

It is better you learn how to do it yourself and there are plenty of resources online where you can find examples. For example:
SQL WHERE Clause[^]

Build up the query step by step until you have the result you want.

Good luck.
 
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