• Looking for a ‘-9’ in a string (A2k2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Looking for a ‘-9’ in a string (A2k2)

    Author
    Topic
    #399236

    Hello All,
    I am using a form control to look up a part number in a ODBC connected table. The right hand part of the string is “-9” for the part numbers I want returned. The hard part is that there is some spaces at the end of the number. I would like to say that there will always be 4 spaces but I cannot say for sure. So…… Is there a way to strip off the spaces at the end of the string and then look for anything that has the “-9”??? Here is an example of one of the part numbers (four end spaces included):
    050-10029-9

    Thanks,
    Mark

    Viewing 1 reply thread
    Author
    Replies
    • #769421

      Try:

      SELECT Trim([MyFieldName]) AS XX
      FROM MyTableName
      WHERE ((Right([MyFieldName],2)=”-9″))

      • #769494

        Shouldn’t that be WHERE Right(Trim([MyFieldName]),2) = “-9” or, alternatively, WHERE Trim([MyFieldName]) Like “*-9”

        • #770426

          Hans,

          The SQL I posted seemed to work but now I am not so sure. In a Select statement with a Where, in which order is the SQL processed?

          James

          • #770438

            Whatever the order of execution, in

            SELECT Trim([MyFieldName]) AS XX
            FROM MyTableName
            WHERE ((Right([MyFieldName],2)=”-9″))

            the WHERE condition is on MyFieldName, not on the trimmed field XX. You won’t notice the difference in a test in Access, since Access automatically trims trailing spaces when you enter data in a text field. But Mark Santos is working with a table in another format, linked via ODBC. Text fields in such a table may well contain trailing spaces.

          • #770439

            Whatever the order of execution, in

            SELECT Trim([MyFieldName]) AS XX
            FROM MyTableName
            WHERE ((Right([MyFieldName],2)=”-9″))

            the WHERE condition is on MyFieldName, not on the trimmed field XX. You won’t notice the difference in a test in Access, since Access automatically trims trailing spaces when you enter data in a text field. But Mark Santos is working with a table in another format, linked via ODBC. Text fields in such a table may well contain trailing spaces.

        • #770427

          Hans,

          The SQL I posted seemed to work but now I am not so sure. In a Select statement with a Where, in which order is the SQL processed?

          James

      • #769495

        Shouldn’t that be WHERE Right(Trim([MyFieldName]),2) = “-9” or, alternatively, WHERE Trim([MyFieldName]) Like “*-9”

      • #769496

        I think you will have to change it to:
        SELECT Trim([MyFieldName]) AS XX
        FROM MyTableName
        WHERE ((Right(Trim([MyFieldName]),2)=”-9″))
        or
        SELECT Trim([MyFieldName]) AS XX
        FROM MyTableName
        WHERE ((Right(XXX,2)=”-9″))

      • #769497

        I think you will have to change it to:
        SELECT Trim([MyFieldName]) AS XX
        FROM MyTableName
        WHERE ((Right(Trim([MyFieldName]),2)=”-9″))
        or
        SELECT Trim([MyFieldName]) AS XX
        FROM MyTableName
        WHERE ((Right(XXX,2)=”-9″))

    • #769422

      Try:

      SELECT Trim([MyFieldName]) AS XX
      FROM MyTableName
      WHERE ((Right([MyFieldName],2)=”-9″))

    Viewing 1 reply thread
    Reply To: Looking for a ‘-9’ in a string (A2k2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: