Solved

ODBC and Ucase and LCase

Posted on 2000-02-28
7
666 Views
Last Modified: 2008-02-26
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
Comment
Question by:umeshkhoje
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2565340
Post some code
0
 
LVL 1

Expert Comment

by:PatrickVD
ID: 2565370
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
 

Author Comment

by:umeshkhoje
ID: 2565433
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: 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.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2565485
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
 
LVL 1

Expert Comment

by:PatrickVD
ID: 2565560
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
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 2565599
«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
 

Author Comment

by:umeshkhoje
ID: 2566858
Thanks for the help.
0

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question