Solved

ODBC and Ucase and LCase

Posted on 2000-02-28
7
647 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 69

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 69

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now