Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ODBC and Ucase and LCase

Posted on 2000-02-28
7
Medium Priority
?
708 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 150 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 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