Soader03
Soader03

Reputation: 351

Error when doing a SQL Server query

I am doing this query in a stored procedure: SELECT TOP 1 [Employe] FROM Transactions WHERE [Employe]=@Name AND Date=@Date

It is supposed to return an employee ID (int). In my application (ASP.NET C#) I get this error when, with a DataReader, I read a line: *Conversion failed when converting the varchar value * to data type int. *

What exactly is the type * ? And I am not trying to convert anything.

Upvotes: 1

Views: 112

Answers (3)

user596075
user596075

Reputation:

Most likely you are passing @Name parameter as a varchar where Employe field is an int field.

Or you could be trying to assign your resulting value of Employe to an int datatype then you would be seeing this error.

Please post your Transactions table definition and your stored procedure code to further troubleshoot.

Upvotes: 0

Greg B
Greg B

Reputation: 14888

Looks like you're sleecting the Employe column which I'm guessing is varchar. I'm assuming you want to select the ID column.

SELECT TOP 1 [ID] FROM Transactions WHERE [Employe]=@Name AND Date=@Date

Upvotes: 3

BG100
BG100

Reputation: 4531

I think probably your @Name parameter is specified as an VARCHAR, but the Employe field in the table is an INT field.

Try this:

SELECT TOP 1 [Employe] FROM Transactions WHERE CAST([Employe] AS VARCHAR)=@Name AND Date=@Date

Upvotes: 0

Related Questions