Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Using Command to input complex sql Post Reply Post New Topic
Author Message
zach18
Groupie
Groupie
Avatar

Joined: 08 Feb 2011
Online Status: Offline
Posts: 46
Quote zach18 Replybullet Topic: Using Command to input complex sql
    Posted: 08 Feb 2011 at 7:06am
so i am using database expert ->ole db (ado) ->selecting the server -> then Add Command. I have a sql statement that accepts two parameters, year and week number. I am having some issues with using the Add Command to Report dialog box. I create the parameters, replace them in the code, but only get errors.

Here is the actual SQL statement...

declare @DesiredYear int

declare @dYear varChar (20)
set @dYear = 2011
set @DesiredYear = @dYear

declare @DesiredWeek int

declare @dWeek as INT
set @dWeek = 5
set @DesiredWeek = @dWeek



This works fine. This what it looks like in the command window

declare @DesiredYear int

declare ?dYear int

set @DesiredYear = {?dYear}

declare @DesiredWeek int

declare ?dWeek as INT


dWeek and dYear are the parameters created in the command view and @DesiredYear and @DesiredWeek are used throughout the sql itselt, hence trying to set the entered parameter to the variable.


IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 08 Feb 2011 at 9:52am
Have you created the parameters at the right of the command window?  If not, that's where you create them.  At that point, you will NOT declare them as variable in your SQL.  Instead, you'll just position your cursor in the command SQL where you want the parameter to be used and then double-click on the parameter or drag it into the SQL editor portion of the window.
 
DO NOT create the parameters in the main report - in order to use them in a command, they MUST be created in the command editor.
 
-Dell
IP IP Logged
zach18
Groupie
Groupie
Avatar

Joined: 08 Feb 2011
Online Status: Offline
Posts: 46
Quote zach18 Replybullet Posted: 09 Feb 2011 at 4:30am
yeah sorry about the lack of detail. So the ?dWeek and ?dYear, are the declared variables. i took the {}'s out as trial and error.

declare @DesiredYear int
set @DesiredYear = {?dYear}

declare @DesiredWeek int
set @DesiredWeek = {?dWeek}

i changed it to this and it worked! Thanks
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.