Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kotsas
Yak Posting Veteran
65 Posts |
Posted - 2002-08-26 : 04:23:34
|
| I create table like this:Create table test (a varchar (30))Than I do this:insert into sasko_test values ('22.5')insert into sasko_test values ('23.5')insert into sasko_test values ('24')Than I do this on SQL SERVER 2000:select * from sasko_test where a = 24and I receive error:Server: Msg 245, Level 16, State 1, Line 1Syntax error converting the varchar value '22.5' to a column of data type int.But this works on SQL SERVER 7.0WHAT IS THE PROBLEM???? |
|
|
Andraax
Aged Yak Warrior
790 Posts |
Posted - 2002-08-26 : 06:21:19
|
| Since the values in the table are of the type varchar, and the value you typed will be interpreted as an integer, the SQL server will try to convert the varchar values to integers. The string '22.5' cannot be converted to an integer. Try:select * from sasko_test where a = '24'or:select * from sasko_test where a = convert(varchar, 24)You should always try to compare values of the same datatypes or do the conversion yourself in a controlled way, or these problems will occur.<edit>Of course you can also store the values in another datatype if that suits you better!</edit>Edited by - andraax on 08/26/2002 06:22:27 |
 |
|
|
kotsas
Yak Posting Veteran
65 Posts |
Posted - 2002-08-26 : 08:58:00
|
| I know this. But why this i working on SQL SERVER 7.0???/ |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-08-26 : 10:48:35
|
| They changed the implicit/explicit rules between the two versions.Comparing a varchar to a char like this is a bit dubious anyway as you get different results if they are both converted to char or both converted to int.Even if you know which way round it does it people who come along after you may not.Don't know if bol mentions what happens - if it doesn't then it can get changed between service packs - or they could release an update to the bol with a service pack.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|