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 2005 Forums
 Other SQL Server Topics (2005)
 Comparison error when using prepared statement

Author  Topic 

phireph0x
Starting Member

2 Posts

Posted - 2008-10-20 : 12:04:58
I'm running a prepared statement against a SQL Server 2005 (SP2) database, and keep receiving the following error(s):


The data types varchar and text are incompatible in the equal to operator.

Statement(s) could not be prepared.


The statement I'm trying to prepare is:

SELECT COUNT(*) FROM test WHERE test_id = ?

The type of test_id is varchar(n), not TEXT... in fact I have no TEXT columns anywhere in the database, yet it seems that the parameter is getting bound as a TEXT type instead of varchar(n).

What do I need to do to get the parameter to be bound as type varchar(n), not TEXT?

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2008-10-21 : 07:48:14
SELECT COUNT(*) FROM test WHERE test_id = ?

What is the actual query - can you give example rather than question-mark ? If it is a parameter value can you show how you fill parameter ?
Go to Top of Page

phireph0x
Starting Member

2 Posts

Posted - 2008-10-21 : 10:05:54
quote:
Originally posted by darkdusky

SELECT COUNT(*) FROM test WHERE test_id = ?

What is the actual query - can you give example rather than question-mark ? If it is a parameter value can you show how you fill parameter ?



The question mark is the parameter that is replaced with a string, using the SQLBindParam() ODBC call. I'm making these calls via ODBC. Example:

SELECT COUNT(*) FROM test WHERE test_id = 'a1b2c3d4'
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-10-22 : 18:42:51
maybe you can exactly determine the content of your parameter when it's crashing?
maybe there are some charaters that can be confounded with binary data?

I don't really know...

Webfred

No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -