Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Oracle and SQL*Server Apostrophe Problem

Posted on 1999-10-15
Medium Priority
Last Modified: 2012-08-14
I have a program that was geared towards Oracle.

This program has many select statements that use Apostrophes around number fields which works fine for Oracle, but SQL*Server does not like this..

Is there a setting in SQL*Server that will allow Apostrophes to be around numbers as well as strings?
Question by:tward
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

Expert Comment

ID: 2133957
No, I am afraid with out changing you tables, you are stuffed. The only other option is to create a view qhich converts the specific field to  text, you would however then not be able to use indexes

Author Comment

ID: 2138426
I'm going to leave it out for other comments/answers.  I have started changing the program but for future case I would like to see if there is any other way!
LVL 43

Expert Comment

ID: 2141672
SQL Server does not allow implicit conversion of datatypes in most cases. Text / character data cannot be implicitly converted to int/real/binary etc. You could use the convert function e.g.,

select x,y,z from xyz where x = convert(int,'nnn')

I don't know whether this is supported under Oracle.
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.


Expert Comment

ID: 2174915
Can you supply an example statement?  I'm not really following what the problem is.


Expert Comment

ID: 2174920
The problem is Oracle allows implicit conversion between numbers and strings i.e
1='1' is true in Oracle but not supported in Sql server

Accepted Solution

cymbolic earned 800 total points
ID: 2310486
You have to bite the bullet and make your program dynamically modify the SQL before you issue it to the database.

Here's another interesting little same type grimble.  SQL Server (T-SQL)delimits dates with single apostrophe, MS Access with pound sign.  

What I have done is to examine the connect string (connect property of connection object) for information about the database type I am connected with, then I have a common routine that all SQL and columns pass through which correctly delimits the columns in each SQL statement based on their type.  Real tough to do if you have inline SQL typed into the program, and no knowldge of the data types for each field.

A more sophisticated method is to use the ODBC driver API calls, and get information on the attributes of the connected DSN, assuming you are using ODBC (that is correctly called, SLOWDBC)

Author Comment

ID: 2312024
That is basically what I had to do.

When I am building the SQL Statement, for each field I check the type to see if it needs apostrophes or not.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

660 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