Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SQL Command Post Reply Post New Topic
Author Message
duck
Newbie
Newbie


Joined: 29 Apr 2009
Online Status: Offline
Posts: 8
Quote duck Replybullet Topic: SQL Command
     Posted: 05 Jun 2009 at 6:52am
I'm using a SQL command to select the data on a report. The report should accept a beginning date parameter and and ending date parameter. The ?rep parameter works fine.

WHERE "SALESREP" = '{?rep}'
AND "DATE" > '{?datedeb}' AND "DATE" < '{?datefin}'

This returns an "Incorrect Syntax Near 2009" error message. What sort of format do I need for the dates?

TIA...
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 05 Jun 2009 at 7:06am
is the column DATE a datetime field and are the parameters datetime as well?  That is the first thing I would check.
 
Just as a question, why are you having a SQL command select the data for your report?
 
The reason I ask, is that I have always used the SQL command to populate parameters for Crystal.  I think that was the original intent, and while it probably works, it may have quirks as I don't think this is the designed function.
 
If you want to write your own SQL, create a view or stored proc and pass the parameters to that.
 
I don't mean to preach or push you to write a report in a certain way, it just that are quite a few people who write reports this way, and then they run into issues as Crystal treats SQL commands in a way different than the report writers 'thought' it should work.
 
With that in mind, if I was writing this for SQL, well, I wouldn't but syntax that is confusing me, is the single quotes around the date parameters and the double quotes around the fields.  Do you have a field called DATE?  Try running your query in your database software (like SQL Server) and see if it is working.  For SS, you would enter the ' around the date, but that is because you are typing it.  If you were comparing it to another datetime field you wouldn't and this may or may not affect the SQL command when the parameter is coming from Crystal...depends on what / how you are entering the data and Crystal is passing it
 
HTH
IP IP Logged
duck
Newbie
Newbie


Joined: 29 Apr 2009
Online Status: Offline
Posts: 8
Quote duck Replybullet Posted: 05 Jun 2009 at 7:18am
I had added a view but couldn't get CR to see it; definitely user error as I haven't found a doc to aid in the process. The SQL command worked, passed integrity checks on the data returned, so I stuck with it. I was able to resolve the parameter issues by removing the WHERE clause all together and just adding the parameters on the report. We have SQL studio to set up the views, how can I access those in CR?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 05 Jun 2009 at 8:18am

just like you would a table.  set the data connection and then in the report use that dataconnection.

I set the datasource in our app to the dataset that I am passing.  I use ADO.Net since it is basically just XML and I can have the dataset write out the XML to a file and then use that develop a report off of.  My reports don't retrieve any data, they just use the data that I pass to them (so I don't have the whole issue of linking to a database and perhaps getting the wrong one)

HTH
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum