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. Database & SysAdmin
  3. Database
  4. MS ACCESS QUery

MS ACCESS QUery

Scheduled Pinned Locked Moved Database
databasehelpcsharpquestion
8 Posts 3 Posters 0 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.
  • J Offline
    J Offline
    jonhbt
    wrote on last edited by
    #1

    Hi I am writing the following SQL command in the MS Access and it is working in access. When I add it to the command string in C# to execute it with the OleDbSqlDataAdapter I get a syntax error. Can someone help please? SELECT USERINFO.Name,DEPARTMENTS.DEPTNAME, main.CHECKTIME FROM (DEPARTMENTS RIGHT JOIN USERINFO ON DEPARTMENTS.DEPTID = USERINFO.DEFAULTDEPTID) INNER JOIN CHECKINOUT as main ON USERINFO.USERID = main.USERID WHERE (main.CHECKTYPE = \"I\" AND main.LOGID = (SELECT MAX(LOGID) FROM CHECKINOUT as last WHERE last.USERID = main.USERID)); I used \" only in the C# part

    _ N 2 Replies Last reply
    0
    • J jonhbt

      Hi I am writing the following SQL command in the MS Access and it is working in access. When I add it to the command string in C# to execute it with the OleDbSqlDataAdapter I get a syntax error. Can someone help please? SELECT USERINFO.Name,DEPARTMENTS.DEPTNAME, main.CHECKTIME FROM (DEPARTMENTS RIGHT JOIN USERINFO ON DEPARTMENTS.DEPTID = USERINFO.DEFAULTDEPTID) INNER JOIN CHECKINOUT as main ON USERINFO.USERID = main.USERID WHERE (main.CHECKTYPE = \"I\" AND main.LOGID = (SELECT MAX(LOGID) FROM CHECKINOUT as last WHERE last.USERID = main.USERID)); I used \" only in the C# part

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      jonhbt wrote:

      SELECT USERINFO.Name,DEPARTMENTS.DEPTNAME, main.CHECKTIME FROM (DEPARTMENTS RIGHT JOIN USERINFO ON DEPARTMENTS.DEPTID = USERINFO.DEFAULTDEPTID) INNER JOIN CHECKINOUT as main ON USERINFO.USERID = main.USERID WHERE (main.CHECKTYPE = \"I\" AND main.LOGID = (SELECT MAX(LOGID) FROM CHECKINOUT as last WHERE last.USERID = main.USERID));

      try this for your string: "USERINFO.Name,DEPARTMENTS.DEPTNAME, main.CHECKTIME FROM (DEPARTMENTS RIGHT JOIN USERINFO ON DEPARTMENTS.DEPTID = USERINFO.DEFAULTDEPTID) INNER JOIN CHECKINOUT as main ON USERINFO.USERID = main.USERID WHERE (main.CHECKTYPE = 'I' AND main.LOGID = (SELECT MAX(LOGID) FROM CHECKINOUT as last WHERE last.USERID = main.USERID));"

      I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

      J 1 Reply Last reply
      0
      • J jonhbt

        Hi I am writing the following SQL command in the MS Access and it is working in access. When I add it to the command string in C# to execute it with the OleDbSqlDataAdapter I get a syntax error. Can someone help please? SELECT USERINFO.Name,DEPARTMENTS.DEPTNAME, main.CHECKTIME FROM (DEPARTMENTS RIGHT JOIN USERINFO ON DEPARTMENTS.DEPTID = USERINFO.DEFAULTDEPTID) INNER JOIN CHECKINOUT as main ON USERINFO.USERID = main.USERID WHERE (main.CHECKTYPE = \"I\" AND main.LOGID = (SELECT MAX(LOGID) FROM CHECKINOUT as last WHERE last.USERID = main.USERID)); I used \" only in the C# part

        N Offline
        N Offline
        Niladri_Biswas
        wrote on last edited by
        #3

        Replace CHECKTYPE = \"I\" with CHECKTYPE = 'I' :)

        Niladri Biswas

        J 1 Reply Last reply
        0
        • N Niladri_Biswas

          Replace CHECKTYPE = \"I\" with CHECKTYPE = 'I' :)

          Niladri Biswas

          J Offline
          J Offline
          jonhbt
          wrote on last edited by
          #4

          i tried but the same syntax error

          1 Reply Last reply
          0
          • _ _Damian S_

            jonhbt wrote:

            SELECT USERINFO.Name,DEPARTMENTS.DEPTNAME, main.CHECKTIME FROM (DEPARTMENTS RIGHT JOIN USERINFO ON DEPARTMENTS.DEPTID = USERINFO.DEFAULTDEPTID) INNER JOIN CHECKINOUT as main ON USERINFO.USERID = main.USERID WHERE (main.CHECKTYPE = \"I\" AND main.LOGID = (SELECT MAX(LOGID) FROM CHECKINOUT as last WHERE last.USERID = main.USERID));

            try this for your string: "USERINFO.Name,DEPARTMENTS.DEPTNAME, main.CHECKTIME FROM (DEPARTMENTS RIGHT JOIN USERINFO ON DEPARTMENTS.DEPTID = USERINFO.DEFAULTDEPTID) INNER JOIN CHECKINOUT as main ON USERINFO.USERID = main.USERID WHERE (main.CHECKTYPE = 'I' AND main.LOGID = (SELECT MAX(LOGID) FROM CHECKINOUT as last WHERE last.USERID = main.USERID));"

            I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

            J Offline
            J Offline
            jonhbt
            wrote on last edited by
            #5

            Nothing happened U tried it that way before and still the same error. The error is in second select statement because when i removed that part it worked. So if there is a way I can replace that sql part it would solve it. The funny thing is that when running that in the access queries it works

            _ 1 Reply Last reply
            0
            • J jonhbt

              Nothing happened U tried it that way before and still the same error. The error is in second select statement because when i removed that part it worked. So if there is a way I can replace that sql part it would solve it. The funny thing is that when running that in the access queries it works

              _ Offline
              _ Offline
              _Damian S_
              wrote on last edited by
              #6

              LOL... that would have been pertinent information beforehand... The second query (or more correctly - subquery) is failing because you are referencing a table that doesn't exist in the query... Consider saving the subquery as a view/query then referencing the saved view/query instead.

              I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

              J 1 Reply Last reply
              0
              • _ _Damian S_

                LOL... that would have been pertinent information beforehand... The second query (or more correctly - subquery) is failing because you are referencing a table that doesn't exist in the query... Consider saving the subquery as a view/query then referencing the saved view/query instead.

                I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

                J Offline
                J Offline
                jonhbt
                wrote on last edited by
                #7

                can you relate me to an example please of how this is done. Thanks

                _ 1 Reply Last reply
                0
                • J jonhbt

                  can you relate me to an example please of how this is done. Thanks

                  _ Offline
                  _ Offline
                  _Damian S_
                  wrote on last edited by
                  #8

                  Save this as a query, call it something like qryMaxLogID

                  SELECT MAX(LOGID) as MaxLogID, UserID FROM CHECKINOUT
                  group by UserID
                  where CHECKTYPE = 'I'
                  Order by UserID;

                  Then, reference it in your existing query like this:

                  "select USERINFO.Name,DEPARTMENTS.DEPTNAME, main.CHECKTIME FROM (DEPARTMENTS RIGHT JOIN USERINFO ON DEPARTMENTS.DEPTID = USERINFO.DEFAULTDEPTID) inner join qryMaxLogID on userinfo.UserID = qryMaxLogID.UserID inner join INNER JOIN CHECKINOUT as main ON qryMaxLogID.MaxLogID = main.LogID;"

                  I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

                  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