locked
Combine 2 sql statement into one RRS feed

  • Question

  • User-1753299103 posted

    Any idea  how to combine the 2 statement data and rstotal:

            var data = db.Query("select *  from Expertise order by MyExpertise").Select((value, index) => new { Index = index / 10, Item = value }).GroupBy(item => item.Index);
            if (data.Any())
            {
                foreach (var group in data)
                { 
                        foreach (var row in group)
                        {
                            var rstotal = db.QueryValue("select Count(idwriterprofile) from profilewriters where MyExpertise LIKE '%'+@0+'%'", row.Item.MyExpertise);
                            @row.Item.MyExpertise @rstotal<br />
                        }
                }
            }

    Sunday, January 31, 2021 8:47 PM

Answers

  • User-1753299103 posted

    I am still working on it. I thought I found the solution.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 3, 2021 9:21 PM

All replies

  • User1535942433 posted

    Hi engcanada,

    According to your description,I don't understand your requirment clearly.Do you need to combind two sql query?If you need this,you could do like this:

    db.QueryValue("select Count(idwriterprofile) from profilewriters where MyExpertise LIKE '%'+@0+'%'", row.Item.MyExpertise),db.Query("select *  from Expertise order by MyExpertise").Select((value, index) => new { Index = index / 10, Item = value }).GroupBy(item => item.Index);

    You could test us more details to us.It will help us to solve your problems.

    Best regards,

    Yijing Sun

    Monday, February 1, 2021 7:29 AM
  • User-1753299103 posted

    Thank you

    Your approach did not work and also does not make sense. The row  in row.Item.MyExpertise  has not even be declared yet. How can be used in the sql statement?

    Regards

    Monday, February 1, 2021 7:08 PM
  • User1535942433 posted

    Hi engcanada,

    You could try Concat() method to combine two query.

    More details,you could refer to below article:

    https://stackoverflow.com/questions/39695922/ef-combine-several-tables-into-one-iqueryable

    Best regards,

    Yijing Sun

    Wednesday, February 3, 2021 8:44 AM
  • User-1753299103 posted

    I am still working on it. I thought I found the solution.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 3, 2021 9:21 PM
  • User1535942433 posted

    Hi engcanada,

    So,what's your problems now?You could to tell us.

    Best regards,

    Yijing Sun

    Thursday, February 4, 2021 6:12 AM
  • User-821857111 posted

    If all you want to do is to get the total number of profilewriters for each MyExpertise, the following should do:

    select MyExpertise,  Count(MyExpertise) as Total from profilewriters group by MyExpertise
    Thursday, February 4, 2021 6:32 AM