Solved

ODBC and Ucase and LCase

Posted on 2000-02-28
7
658 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
consolidate or create a new vba code for performing tasks 5 66
VBA open file from excel cell 4 42
using Access 8 68
Microsoft Access combo box help 2 44
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

785 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