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
 SQL Server Development (2000)
 Error while using prepared statement

Author  Topic 

rameshkg
Starting Member

22 Posts

Posted - 2004-06-18 : 10:56:44
Hi,

I am using an UPDATE prepared statement to update a table of SQL Server 2000. I am using parameters in the UPDATE statement and these parameters will be passed with values at runtime. The error i am getting, BEFORE I PASS VALUES TO THE PARAMETERS is as follows :

W 5296 (java_extensions.cxx:956): Session.checkConnection(): Microsoft SQLServer error message: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error

The Prepared Statement which i am using is as follows :

Update TEMP set X_1 = ?, Y_1 = ?, Z_1 = ?, W_1 = ? where X_1 = ?

Any idea as to what is the problem ? Is it because of underscores in column names OR because of '?' as parameter indicators ?

I verified the column names, syntax etc., everything is OK.

Your early input is appreciated.

Thanks
Ramesh

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-06-18 : 11:08:27
maybe?

? => @X_1

Corey
Go to Top of Page

rameshkg
Starting Member

22 Posts

Posted - 2004-06-18 : 11:19:28
Thanks for the quick reply.

Sorry... i didn't get you...

Do you want me to replace only for the WHERE clause as @X_1 instead of X_1=?.

What about other parameters specified for X_1, Y_1 etc., ?
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-06-18 : 11:30:28
Sorry... something like this?

Update TEMP set X_1 = @newX_1, Y_1 = @Y_1, Z_1 = @Z_1, W_1 = @W_1 where X_1 = @X_1


Corey
Go to Top of Page

rameshkg
Starting Member

22 Posts

Posted - 2004-06-18 : 11:36:32
Thanks corey, i will try that...

What about INSERT statements ? Can i use in the same way, like INSERT INTO TEMP (X_1,Y_1,Z_1,W_1) values(@X_1,@Y_1,@Z_1,@W_1).

Also, from this we can infer that, in SQL Server, we have to use @<col name> to pass parameters instead of '?'. Hope i am correct.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-06-18 : 11:40:42
@ is used to identify a local variable

Column names are simply that

And an UPDATE and An INSERT are two different oprations

Do you have SQL Server Client tools installed?

Do you know what Enterprise Manager, Query Analyzer, and Books Online are?



Brett

8-)
Go to Top of Page

rameshkg
Starting Member

22 Posts

Posted - 2004-06-18 : 11:46:48
Yes , i know Query Analyzer eventhough i don't know how to use it. My collegue tried using ? as parameter in query analyzer. It gave the above error message, naturally, since, i think we can't execute the prepared statement, just like that, without executing through a client like ASP etc.,

My requirement is to use both UPDATE and INSERT statements using prepared statement and by passing parameters to both of them.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-06-18 : 12:53:17
quick examples:

Declare @var1 int,
@var2 nvarchar(10)

Set @var1 = 5
Set @var2 = 'pizza'

Update yourTable
Set
col1 = @var1,
col2 = @var2

Set @var1 = 7
Set @var2 = 'beer'

Insert Into your table
Select
col1 = @col1,
col2 = @var2

In ASP:

sqlstr = "Update yourTable Set col1=" & var1 & ", col2='" & var2 & "' where col1=<condition>"


Corey
Go to Top of Page
   

- Advertisement -