Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 727
  • Last Modified:

ODBC and Ucase and LCase

I am working with a application which has backend as Access or SQL Server
The application should be independent of the backend database.
In some SQL I am trying to use the String functions  like lcase, Ucase or Trim . This functions work fine with Access database when connected through DSN, but When I am connected to SQL Server database through DSN its giving me trouble. Any solutions?
0
umeshkhoje
Asked:
umeshkhoje
  • 2
  • 2
  • 2
  • +1
1 Solution
 
MarineCommented:
Post some code
0
 
PatrickVDCommented:
For the Trim there is a small workaround... you could use the LTRIM and RTRIM equivalents... they're available in Access AND Sql Server...

But the UCase/LCase is supposed to be UPPER/LOWER in Transact-SQL...

Depending on what you are trying to do... you might need to do some specific processing.. depending on the backend database or otherwise you should avoid using those functions at all.
0
 
umeshkhojeAuthor Commented:
For e.g. there is simple SQL statement
which will check the UserName from the password table.

ssql = "Select * from Users Where Lcase(Trim(UserName)) = '" & Lcase(Trim(sUserName)) & "'"

Now when I am using this sql to open a recordset with ADO and Access using DSN
it works fine. But when the same SQL is tried with SQL SERVER and  ODBC it gives me an error.

The same thing happens with UPPER and LOWER functions they work fine with SQL SERVER but not with Access.

I am wondering how I can make my application completely independent of the backend database.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Éric MoreauSenior .Net ConsultantCommented:
Sorry, but this can't be done automatically!!!

You need some code like this:

if Access then
ssql = "Select * from Users Where Lcase(Trim(UserName)) = '" & Lcase(Trim(sUserName)) & "'"
else
ssql = "Select * from Users Where lower(rTrim(UserName)) = '" & Lower(rTrim(sUserName)) & "'"
end if
0
 
PatrickVDCommented:
As far as I can see, there is only 1 way to make your code database independent...
(I'm taking into account the SQL statement you gave as an example)

You have to make sure that ALL your usernames are stored in the same case in the database (lowercase in your sample)... then you don't need to perform the case manipulation on your field in the sql statement, but can simple convert the parameter string sUserName to lowercase in VB before adding it to the SQL statement (as you did in your sample).
This is the only way to make it work on both database systems.
0
 
Éric MoreauSenior .Net ConsultantCommented:
«I am wondering how I can make my application completely independent of the backend database. »

This is really hard to do since you found a problem in the naming of functions between Access and SQL. What if you go to Oracle? You will have other problems. For example, Joins in Access and SQL Server are the same (if you use INNER JOIN or LEFT JOIN) but Oracle doesn't recognize this.

You need some code in your application that handles that differences!
0
 
umeshkhojeAuthor Commented:
Thanks for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now