Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. SQL to LINQ

SQL to LINQ

Scheduled Pinned Locked Moved LINQ
databasecsharplinqquestion
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    faramarz sunseas
    wrote on last edited by
    #1

    Hi . How can I change this SQL query to LINQ :

    SELECT SUM(Grades.Grade * Lessons.LesTotalUnit) / SUM(Lessons.LesTotalUnit) AS avg FROM Grades INNER JOIN Lessons ON Grades.LesCode = Lessons.LesCode WHERE (Grades.StNo = @stno) AND (Grades.EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_1 WHERE (StNo = @stno))) AND (Grades.Semester IN (SELECT MAX(Semester) AS Expr1 FROM Grades AS Grades_2 WHERE (StNo = @stno) AND (EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_3 WHERE (StNo = @stno)))))

    E R 2 Replies Last reply
    0
    • F faramarz sunseas

      Hi . How can I change this SQL query to LINQ :

      SELECT SUM(Grades.Grade * Lessons.LesTotalUnit) / SUM(Lessons.LesTotalUnit) AS avg FROM Grades INNER JOIN Lessons ON Grades.LesCode = Lessons.LesCode WHERE (Grades.StNo = @stno) AND (Grades.EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_1 WHERE (StNo = @stno))) AND (Grades.Semester IN (SELECT MAX(Semester) AS Expr1 FROM Grades AS Grades_2 WHERE (StNo = @stno) AND (EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_3 WHERE (StNo = @stno)))))

      E Offline
      E Offline
      Emmanuel Medina
      wrote on last edited by
      #2

      Can you format your code? it's harder than necessary to read it as you posted it. If you want to learn LINQ I recommend 101 LINQ Samples[^] as well as getting and using LINQPad[^] which is a pretty good tool for learning LINQ and try code snippets. For learning how to convert SQL to LINQ, this resource[^] is quite useful (it's in VB but it should be pretty easy to do the translation to C#). If you can't invest the time to learn right now (although I highly recommend it) you can use Linqer[^]

      If you think you can do a thing or think you can't do a thing, you're right - Henry Ford Emmanuel Medina Lopez

      1 Reply Last reply
      0
      • F faramarz sunseas

        Hi . How can I change this SQL query to LINQ :

        SELECT SUM(Grades.Grade * Lessons.LesTotalUnit) / SUM(Lessons.LesTotalUnit) AS avg FROM Grades INNER JOIN Lessons ON Grades.LesCode = Lessons.LesCode WHERE (Grades.StNo = @stno) AND (Grades.EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_1 WHERE (StNo = @stno))) AND (Grades.Semester IN (SELECT MAX(Semester) AS Expr1 FROM Grades AS Grades_2 WHERE (StNo = @stno) AND (EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_3 WHERE (StNo = @stno)))))

        R Offline
        R Offline
        Raushank03
        wrote on last edited by
        #3

        http://techgurulab.com/course/sql-tutorial/[^] This link is help to basic concept on SQL

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups