Results 1 to 18 of 18

Thread: SQL Problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    SQL Problem

    Hi to all:

    I have been a problem with SQL when I try to order the database (ACCESS),by name like:

    João

    António

    I Think the problem it was with (ã) and (ó)...and my question is:

    This is normal?Which way can I resolve this?

    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL Problem

    It is normal I'm afraid, and the problem is the accented characters.

    The reason this happens is because they are not seen as letters, but other ascii characters (just as - and £ would be). As sorting is done by ascii code, this provides odd results.

    I'm afraid I dont know of a way to deal with it nicely, all I can think of is to have an extra column in the database which is a copy of the first, but without the accents. Alternatively you could replace the accented characters with their non-accented version in the Order By clause.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL Problem

    Alternatively you could replace the accented characters with their non-accented version in the Order By clause.
    And can you tell me the way I can do this,because this is my code in order Clause:


    VB Code:
    1. Private Sub Option1_Click(Index As Integer)
    2.  
    3. Dim aSQL As String
    4. aSQL = "Select * from exposicao "
    5.  
    6.  If Index = 1 Then aSQL = aSQL & " ORDER BY registo"
    7.  If Index = 2 Then aSQL = aSQL & " ORDER BY expositor"
    8.  If Index = 3 Then aSQL = aSQL & " ORDER BY n_socio"
    9.  If Index = 4 Then aSQL = aSQL & " ORDER BY stamfpo"
    10.  If Index = 5 Then aSQL = aSQL & " ORDER BY stamfocip"
    11.  If Index = 6 Then aSQL = aSQL & " ORDER BY nomesocio"
    12.  
    13. Set rsexposicao = db.OpenRecordset(aSQL)
    14. Set Data1.Recordset = rsexposicao
    15.  
    16.  
    17. End Sub

    Thanks

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: SQL Problem

    Do you have a question about this? This would be a little quicker, as only one condition would execute. Each IF statement would be evaluated in your code.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Option1_Click(Index As Integer)
    4.   Dim aSQL As String
    5.   aSQL = "Select * from exposicao "
    6.  Select Case Index
    7.  Case Is = 1
    8.     aSQL = aSQL & " ORDER BY registo"
    9.  Case Is = 2
    10.     aSQL = aSQL & " ORDER BY expositor"
    11.  Case Is = 3
    12.     aSQL = aSQL & " ORDER BY n_socio"
    13.  Case Is = 4
    14.     aSQL = aSQL & " ORDER BY stamfpo"
    15.  Case Is = 5
    16.     aSQL = aSQL & " ORDER BY stamfocip"
    17.  Case Is = 6
    18.     aSQL = aSQL & " ORDER BY nomesocio"
    19.  End Select
    20.  Set rsexposicao = db.OpenRecordset(aSQL)
    21.  Set Data1.Recordset = rsexposicao
    22. End Sub

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL Problem

    This is the other code I have for find a name:

    VB Code:
    1. Private Sub Text2_Change()
    2. Dim aSQL, Letra As String
    3. Letra = Text2.Text & "*"
    4. aSQL = "Select * from exposicao "
    5. If Option1(1).Value = True Then
    6. aSQL = aSQL & "Where registo Like '" & Letra & "'  Order By registo "
    7. End If
    8. If Option1(2).Value = True Then
    9. aSQL = aSQL & "Where expositor Like '" & Letra & "'  Order By expositor "
    10. End If
    11. Set rsexposicao = db.OpenRecordset(aSQL)
    12. Set Data1.Recordset = rsexposicao
    13. Grelha
    14. mostrar
    15. End Sub

    if I put for example in the box text2 "João" The VB returns a error!

    Any way to resolve this?

    Thanks

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL Problem

    What I meant was something like this:
    Code:
    Order By Replace(Replace(registo,'ã','a'),'ó','o') "
    Note that the syntax you use to replace will vary by DBMS. (I think this will work for Access).

    I have no idea why you get an error using Like, what is the error that is shown, and when does it get displayed (whcih line of code)?

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL Problem

    This is the line a get the error:

    Run time error 3420

    VB Code:
    1. Set rsexposicao = db.OpenRecordset(aSQL)

    I agree with you...I don't now why I have thie error...very strange


    Thanks

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL Problem

    I don't know the meaning of all the error codes, so you might like to let us know what the message is too

    It would also be useful to know what the value of aSQL is at the time, so put this just before it:

    VB Code:
    1. Debug.Print aSQL
    ..and post the SQL that is printed to the Immediate window (press Ctrl-G if it isn't visible).

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL Problem

    This is the message when I get the error:


    Select * from exposicao Where nomesocio Like 'jo*' Order By nomesocio

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: SQL Problem

    You gave us the error number but what is the error message?

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL Problem

    The error is:

    Error 3420
    "Object invalid or no longer set"

  12. #12
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Up State NY
    Posts
    525

    Re: SQL Problem

    Quote Originally Posted by sacramento
    This is the message when I get the error:
    Select * from exposicao Where nomesocio Like 'jo*' Order By nomesocio
    Its definately the accented letter a thats doing it. Try the replace line in the above section. That MIGHT do it. Or... Repace the accented letters in the column names.

    Good luck

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: SQL Problem

    Or, create a new column without the characters in it, so you could also return the accented character field. I think the LIKE statement doesn't like accented characters.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL Problem

    but create a column without accented it's not a easy way no? or not?
    because this must be do when I save all the fields in the column and make a copy to that column...not a easy way no?????

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: SQL Problem

    Can you find a field if you don't use Like? That way we'd know if it is a problem with Access (which might be able to be changed) or the LIKE statement (which likely can't be if we can't change Access.

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL Problem

    Quote Originally Posted by sacramento
    The error is:

    Error 3420
    "Object invalid or no longer set"
    That sounds as if the db object is no longer valid, have you closed it somewhere else?

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL Problem

    Hi guys:

    I had decided put a piece of the project here to all see the problem

    When in the project please order by "nome sócio" and the tipe in the box "jo" and the project get the error we have speak here!


    Thanks
    Attached Files Attached Files

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: SQL Problem

    hi:
    NO comments????

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