Link to home
Start Free TrialLog in
Avatar of qbjgqbjg
qbjgqbjgFlag for United States of America

asked on

crystal reports SQL Command

I have an sql command that works, but when I try to add parameters it doesn't. I get Failed to retrieve data from Database. Invalid Column Name E. I tried putting quotes around the employee # when I entered it, Then I got invalid column name E-004525 (the no I entered.
I have the parameter created as EmpNo String. I intended to also create a paramter for fromYear, I had already tried it with both, but it was not working so I was trying one at a time. This is something I have done before without a problem. This is Crystal XI.
from-Crystal-Command.txt
Avatar of Mike McCracken
Mike McCracken

IS this a stored procedure or are you using a Crystal command?

How are you adding the parameter?

mlmcc
Avatar of qbjgqbjg

ASKER

It is a command. I am adding the parameter with Create in the command window.
When you save and close the command, it asks for values for the parameter, does that work?

How did you use the parameter in the command?

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of James0628
James0628

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK, I will try that. Any idea as to why this is suddenly an issue. I have used commands with parameters quite a lot, and not had this problem.
It worked. But I am still wondering why tis was an issue, since I have used commands with paramters before without having to do the quotes.
Is the field a text field of numbers?  
If so it was probably interpreted as comparing a string to a number
'123' = 123

mlmcc
It depends on the type of value in the parameter, and how you're using it.

 If you don't put the quotes around a string parameter and you enter a number, then you won't get an error, but the parameter may or may not work.

 For example, if you enter 123, SQL will just see that as a number.  If you're comparing that to a string column, SQL will just do an implicit conversion, so you won't get an error, but you may or may not get the results that you're looking for.  If SQL converts the column to a number, then 123 would match rows with values like '123', '123.0' and '0123' in that column.  OTOH, if SQL converts the number from the parameter (123) to a string ('123'), then that would only match the rows that had '123' in that column (and not '123.0' or '0123').

 But if you don't put quotes around the parameter and you enter something like E-004525, you end up with

set @EmpNo = E-004525

 and SQL doesn't know what E-004525 is.

 James