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 |
cyberpd
Yak Posting Veteran
60 Posts |
Posted - 2007-10-30 : 06:50:56
|
I am using Sql Server 2000.i have got a table with field name productid (int), productname (varchar) respectively.i am firing a query Select * From MST_PD_ITEM Where Productid = 2907 it returns 1 row.i am firing a second querySelect * From MST_PD_ITEM Where Productid = '2907' it is returning the same row!!!How is this possible as the productid field is integer, the second query should result an error.any help is appreciated. |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-30 : 07:09:31
|
It is called implicit conversion. SQL Server tries to implicitly convert varchar value '2907' to the data type of the column which is integer. In this case, it succeds in doing so, otherwise you would get an error.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
cyberpd
Yak Posting Veteran
60 Posts |
Posted - 2007-10-30 : 07:20:42
|
Thanks for the prompt reply.But sir, this is absolutely not acceptable.I would want the sql server to throw the error that i would handle properly...Could you please suggest how to stop this?thanks and regards. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-30 : 08:24:53
|
As long as you give numbers within single it wont throw any error. Why does it matter to you?You should handle that when coding MadhivananFailing to plan is Planning to fail |
 |
|
KenW
Constraint Violating Yak Guru
391 Posts |
Posted - 2007-10-30 : 14:23:14
|
quote: Originally posted by cyberpd Thanks for the prompt reply.But sir, this is absolutely not acceptable.I would want the sql server to throw the error that i would handle properly...Could you please suggest how to stop this?thanks and regards.
But sir, this is just how most SQL engines work. :-) So there is no stopping it, unless you do it in your front end application. |
 |
|
|
|
|