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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Typical Query behaviour..

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 query
Select * 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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

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.
Go to Top of Page

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

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -