473,473 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Syntax question

Say I use the following SQL statement to create a table

CREATE TABLE BATCH (
BATCHNUM NUMERIC(5) NOT NULL,
COMPID CHAR(2) NOT NULL,
AMOUNT NUMERIC(9,2) NOT NULL,
BDATE DATE NOT NULL,
EDIREF CHAR(15),
FLAG CHAR(1) NOT NULL )

What is the exactly different between these two select statements

SELECT * FROM BATCH WHERE COMPID = '1A' AND AMOUNT = '123.45'
SELECT * FROM BATCH WHERE COMPID = '1A' AND AMOUNT = 123.45

Now, my logic was that if I passed a real number as a string value ie
'123.45' ( 0x3132332E343500 char array of 7 bytes long) that the
database would be much better at accurately (since not all real numbers
can be 100% accurately represented in binary) represently the value
itself verus the client. Am I completely off base with my logic?

The reason I ask is because when I perform the first statement more
than twice in a row it says no rows found however the 2nd statement
works every time. If I close my ODBC connection and restart it and I
can repeat the statement over and over and get the correct results. Why
is this?

Should I never pass any values besides strings using ''? If so why
doesn't the database return an error with my SQL statement?

Eric

Jul 23 '05 #1
1 1050
Wescotte (we******@earthlink.net) writes:
Say I use the following SQL statement to create a table

CREATE TABLE BATCH (
BATCHNUM NUMERIC(5) NOT NULL,
COMPID CHAR(2) NOT NULL,
AMOUNT NUMERIC(9,2) NOT NULL,
BDATE DATE NOT NULL,
EDIREF CHAR(15),
FLAG CHAR(1) NOT NULL )

What is the exactly different between these two select statements

SELECT * FROM BATCH WHERE COMPID = '1A' AND AMOUNT = '123.45'
SELECT * FROM BATCH WHERE COMPID = '1A' AND AMOUNT = 123.45

Now, my logic was that if I passed a real number as a string value ie
'123.45' ( 0x3132332E343500 char array of 7 bytes long) that the
database would be much better at accurately (since not all real numbers
can be 100% accurately represented in binary) represently the value
itself verus the client. Am I completely off base with my logic?
Yes. SQL Server has a datatype prededence, and in expressions with
different datatypes, types with lower precendence are converted to
higher (if there is an implicit conversion). '123.45' is varchar,
and AMOUNT is numeric, and numeric has higher precedence than varchar,
so the string is converted to a numeric value. Note also that 123.45
is indeed a numeric literal, and thus exact.
The reason I ask is because when I perform the first statement more
than twice in a row it says no rows found however the 2nd statement
works every time. If I close my ODBC connection and restart it and I
can repeat the statement over and over and get the correct results. Why
is this?


That's a little funny, and I don't have an answer for what is going on.
But there is no reason to put numbers into strings.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: Aaron Walker | last post by:
Greetings, I'm attempting to write my first *real* template function that also deals with a map of strings to member function pointers that is making the syntax a little tricky to get right. ...
2
by: bor_kev | last post by:
Hi, First of all, i want to use the new managed class syntax and STL.NET under Microsoft Visual (C++) Studio 2005 Beta. I read in a Microsoft...
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
3
by: astromog | last post by:
I have some significantly extended syntax for Python that I need to create a reference implementation for. My new syntax includes new keywords, statements and objects that are sort of like classes...
11
by: deppy_3 | last post by:
Hi! The syntax of fputs() is similar with the syntax of fgets(); For example if we have:fgets(str,maxlen,stdin) which is the syntax of the fputs();
8
by: Smithers | last post by:
Are there any important differences between the following two ways to convert to a type?... where 'important differences' means something more profound than a simple syntax preference of the...
2
by: berrylthird | last post by:
This question was inspired by scripting languages such as JavaScript. In JavaScript, I can access members of a class using array syntax as in the following example: var myInstance:myClass = new...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
6
by: Daniel | last post by:
I hope this question is OK for this list. I've downloaded Rpyc and placed it in my site packages dir. On some machines it works fine, on others not so much. Here is one error I get when I try...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.