Results 1 to 8 of 8

Thread: Re:SQL syntax for access

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    101

    Re:SQL syntax for access

    is it valid syntax to refer to a field in a db ilke this:

    adoRecordset!Orders.OrderID ?

    i have to do this because my SQL statement needs to distinguish this field form anothre field with the same name in an other table?

  2. #2
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I cannot tell but you can always do something like this:

    SELECT Orders.OrderID As O_OrderId, Items.OrderID As I_OrderId FROM Orders, Items WHERE SellID = 1
    And then you can use it like:
    VB Code:
    1. adoRecordset!O_OrderID
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    101
    that did not work

    here is my sql statement that is generated from access

    SELECT Orders.OrderID, Orders.CustomerID, Orders.StartDate, Orders.ExpiryDate, Magazines.Price, Orders.Status
    FROM Magazines INNER JOIN Orders ON Magazines.MagazineID = Orders.MagazineID


    Debug.Print adoRecordset!OrderID, adoRecordset!CustomerID, adoRecordset!StartDate, adoRecordset!ExpriyDate,

    is there an error in here?

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Yes!! The error is that you did not do what I told you to.

    VB Code:
    1. "SELECT Orders.OrderID [b]AS O_OrderID[/b], " & _
    2.   "Orders.CustomerID AS [b]O_CustomerID[/b], " & _
    3.   "Orders.StartDate [b]AS O_StartDate[/b], Orders.ExpiryDate [b]AS O_ExpriyDate[/b], " & _
    4.   "Magazines.Price, Orders.Status " & _
    5.   "FROM Magazines INNER JOIN Orders ON Magazines.MagazineID = Orders.MagazineID"
    6.  
    7. Debug.Print adoRecordset!O_OrderID, adoRecordset!O_CustomerID, _
    8.   adoRecordset!O_StartDate, adoRecordset!O_ExpriyDate
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    101
    I DID DO THAT ! I WAS LISTENING! but it aint working ! the error message that i am getting is :

    item cannot be found in the collectin corresponding to the requested name or ordinal

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    As far as I can tell
    SELECT Orders.OrderID, Orders.CustomerID, Orders.StartDate, Orders.ExpiryDate, Magazines.Price, Orders.Status
    FROM Magazines INNER JOIN Orders ON Magazines.MagazineID = Orders.MagazineID
    is a perfectly valid SQL statement.

    You're not selecting multiple fields with the same field name.

    Use McBrains suggestion if you plan to extract fields from multiple tables where the names of the fields are the same.

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Try this:

    VB Code:
    1. "SELECT Orders.OrderID AS O_OrderID, " & _
    2.   "Orders.CustomerID AS O_CustomerID, " & _
    3.   "Orders.StartDate AS O_StartDate, Orders.ExpiryDate AS O_ExpriyDate, " & _
    4.   "Magazines.Price, Orders.Status " & _
    5.   "FROM Magazines INNER JOIN Orders ON Magazines.MagazineID = Orders.MagazineID"
    6.  
    7. Debug.Print adoRecordset!O_OrderID
    8. Debug.Print  adoRecordset!O_CustomerID,
    9. Debug.Print adoRecordset!O_StartDate
    10. Debug.Print adoRecordset!O_ExpriyDate
    and tell me which line do you get the error at.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    101
    sorry yall! i forgot to change one of the field names to one of the alisas ! my bad !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width