Results 1 to 10 of 10
  1. #1
    hellfire45 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2015
    Posts
    24

    Right Function SQL syntax help

    So I've got this column that I am aliasing as per the following: dbo_Entities.firstname AS [Loan#]

    I need two calculated columns based off that column. One that takes the right most character (regardless of if it is a character or digit) and one that takes the right 2 most characters (regardless of if it is a character or digit). Can somebody help me out by writing the bit of SQL so I can see how this is done? I'm really unfamiliar with the SQL in MS Access.

    thank you so much!

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Try the Right function Right("TheString",2) will return ng and Right("TheString",1) will return g

  3. #3
    hellfire45 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2015
    Posts
    24
    I'm sorry. It's possible I'm a little slow. In the GUI, I've got this written:

    L: Right([dbo_entities.firstname],1)

    I also tried the following:

    L: Right([firstname],1)
    L: Right([loan#],1)
    L: Right('Firstname',1)

    I'm sorry but none of these are working.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Where are you trying to return this calculation?
    In a query, form, report, etc?

    If in a Query, can you paste your SQL code for that query here?

  5. #5
    hellfire45 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2015
    Posts
    24
    It's a query in ACCESS. The query is kinda enormous. They've got me pulling back over 130 columns from 12 tables. I guess I can paste a condensed version below. Thanks! The dbo_Entities.firstname AS [Loan#] is actually a 9 digit integer. They have the name in the database as "firstname" but its actual a loan#. The RIGHT function I'm trying to use is on the end.

    Thanks again!


    Code:
    SELECT dbo_Entities.EntityID AS [File#], dbo_Entities.MiddleName AS FHLMC, dbo_Entities.firstname AS [Loan#], Right([dbo_entities.firstname],1) AS L
    
    FROM dbo_Entities

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Code:
    SELECT dbo_Entities.EntityID AS [File#], dbo_Entities.MiddleName AS FHLMC, dbo_Entities.firstname AS [Loan#], Right([dbo_entities.firstname],1) AS L
    FROM dbo_Entities
    That is valid Access query Syntax.
    What happens when you try to run this query?
    Are you getting an error message (if so, exactly what does it say),
    or are you getting unexpected results (if unexpected results, please provide a few data examples)?

  7. #7
    hellfire45 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2015
    Posts
    24
    It's not giving me an error, it's just giving me nothing. Blank column.

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Sounds like you may have a blank space (or spaces) at the end of your string, so that is what it is returning.
    Try this:
    Code:
    Right(Trim([dbo_entities.firstname]),1)
    Does that make a difference?

    If not, see what this returns:
    Code:
    Len([dbo_entities.firstname])
    That should return the length of the firstname field. Does the value it return seem right to you?
    If you have an entry like "Bob" and it returns something like 5 instead of 3, you know that there are some extra spaces or special characters causing issues.

  9. #9
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    I would Also try.
    Code:
    Right(Val([dbo_entities.firstname]),1)

  10. #10
    hellfire45 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2015
    Posts
    24
    This fixed it. thanks!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Syntax error 3134 for Add function
    By gaker10 in forum Programming
    Replies: 9
    Last Post: 06-16-2014, 12:06 PM
  2. Replies: 4
    Last Post: 02-28-2014, 10:57 PM
  3. Function Syntax
    By RayMilhon in forum SQL Server
    Replies: 4
    Last Post: 03-15-2013, 01:40 PM
  4. simple syntax for putting a variable into a function
    By markjkubicki in forum Programming
    Replies: 2
    Last Post: 11-02-2012, 09:46 AM
  5. IIF function syntax
    By kris335 in forum Access
    Replies: 5
    Last Post: 09-13-2011, 11:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums