Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: how to add a list of paramers i SQAL command Post Reply Post New Topic
Page  of 2 Next >>
Author Message
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Topic: how to add a list of paramers i SQAL command
     Posted: 03 Mar 2013 at 2:59pm
Hi
Is there any way I can import a text file like
CD Current day
CW Current week
CM current month
CQ current quarter
CY current year
CFY current financial year
PD previous day
PW previous week
 
--
--
--
--
 
in the SQL command? when you intend to add parameters; it only allows to add one by one. Then in the prompt, it will display many of these instead of a pickup list.
While I can import a text file into the parameter fields of Field Explorer like the above. But when I did, the SQL command cannot 'see' them.
Please advise
JS
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 04 Mar 2013 at 3:56am
Do you want to use these as values for your parameter?  If so, it's actually fairly easy to do:
 
1.  Create the parameter in the Command. This will create a parameter that is not a list like you want.
 
2.  After saving the Command, go to the parameters section of the main report and modify the parameter to include a list of values - from here you should be able to point it to your text file.
 
-Dell
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 04 Mar 2013 at 11:32am
Hi Dell,
 
Ah! I did not realized that I can still edit the parameters in Field Explorer once I created the same parameters in SQL commad. Thanks a lot!
 
I will try then
 
John
 


Edited by johnwsun - 04 Mar 2013 at 11:34am
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 27 Mar 2013 at 2:55pm
Hi Dell,
 
for SQL command which you helped construct earlier on asbelow, am I able to integrate with a function for processing date range when user select current date, previous date, month, quarter, year, financial year:
 
prompts for date range:
CD Current day
CW Current week
CM current month
CQ current quarter
CY current year
CFY current financial year
 
to put the below into a custom function:
select break_type
 CASE 'CD':
      LDTE = DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)    -- current date
 CASE 'CW':
             LDTE BETWEEN dateadd(week, datediff(week, 0, (getdate())), 0) AND    --as beginning_of_this_week
    dateadd(week, datediff(week, 0, (getdate())), 6)                   --as ending_of_this_week
 CASE 'CM':
      LDTE BETWEEN DATEADD(month, datediff(month, 0, (getdate())), 0)  AND  -- first day of the month
  convert(datetime, convert(varchar(10), getdate(), 101))               -- last day of the month 
 CASE 'CQ':
                LDTE BETWEEN DATEADD(qq, DATEDIFF(qq,0,getdate()), 0) AND             --first day of the quarter
  dateadd(dd,-1,dateadd(qq,1,DATEADD(qq, DATEDIFF(qq,0,getdate()), 0))) -- last day of the quarter
 CASE 'CY':
                LDTE BETWEEN DATEADD(yy, DATEDIFF(yy,0,getdate()), 0) AND                -- first day of the year
                DATEADD(year, DATEDIFF(year, -1, getdate()), -1)                         --  last day of the year
 CASE 'CFY' :
  LDTE BETWEEN = cast('01-Jul-' + cast( case when datepart(mm,getdate()) in (4,5,6,7,8,9,10,11,12) then DATEPART(yy,getdate())
             else DATEPART(yy,getdate())-1
               end as varchar) as datetime) AND                        -- first day of the 1/7/XXXX financial year
                              cast('30-Jun-' + cast( case when datepart(mm,getdate()) in (4,5,6,7,8,9,10,11,12) then DATEPART(yy,getdate())
                else DATEPART(yy,getdate())+1
               end as varchar) as datetime)                              --  last day of the 30/06/XXXX financial year    
 CASE 'PD':
  LDTE = DATEADD(day, DATEDIFF(day, 0, GETDATE()), -1)       -- previous date
 CASE 'PW' :
                LDTE =
 CASE 'PM':
              
                 DATEADD(month, DATEDIFF(month, 0, GETDATE()), -1)
 CASE 'PQ':
 CASE 'PY' :
 CASE 'PFY':
  
 
the exisitng SQL command in the report:
 
SELECT   'Issues' as Record_Type,
CASE WHEN LTP1.TYP = N'LINE' THEN
(CASE WHEN H1.HEAD IS NULL THEN N'None' ELSE H1.HEAD END)
ELSE
(CASE WHEN H12.HEAD IS NULL THEN N'None' ELSE H12.HEAD END)
END as Head,  COUNT(*) AS Item_Count
FROM OND
INNER JOIN BFS ON OND.IRN = BFS.IRN
INNER JOIN ICO ON OND.ITM = ICO.IRN
INNER JOIN MAIN ON ICO.COL = MAIN.IRN
LEFT OUTER JOIN LOCLNK L1 ON OND.LOC = L1.IRN
LEFT OUTER JOIN LTP LTP1 ON OND.LOC = LTP1.IRN
LEFT OUTER JOIN HEADING H1 ON L1.LNK = H1.IRN
LEFT OUTER JOIN HEADING H12 ON L1.IRN = H12.IRN
WHERE LDTE BETWEEN {?start_date} AND {?end_date} AND BFS.CODE = N'IDALBY'  AND NOT MAIN.XCODE IN ('EBOOK', 'MDEVICE') AND (( 'ALL' IN {?location} ) OR (OND.LOC IN {?location}) OR (L1.LNK IN {?location}))
GROUP BY 
CASE WHEN LTP1.TYP = N'LINE' THEN
(CASE WHEN H1.HEAD IS NULL THEN N'None' ELSE H1.HEAD END)
ELSE
(CASE WHEN H12.HEAD IS NULL THEN N'None' ELSE H12.HEAD END)
END
UNION ALL
SELECT   'Reservations' as Record_Type, 
CASE WHEN LTP1.TYP = N'LINE' THEN    
  (CASE WHEN H1.HEAD IS NULL THEN N'None' ELSE H1.HEAD END)  
     ELSE    
 (CASE WHEN H12.HEAD IS NULL THEN N'None' ELSE H12.HEAD END)
END,    COUNT(*)AS Item_Count
FROM RVP   
INNER JOIN RVC ON RVP.IRN = RVC.IRN  
INNER JOIN BFS ON RVP.IRN = BFS.IRN  
LEFT OUTER JOIN LOCLNK L1 ON RVP.PLOC = L1.IRN  
LEFT OUTER JOIN LTP LTP1 ON RVP.PLOC = LTP1.IRN  
LEFT OUTER JOIN HEADING H1 ON L1.LNK = H1.IRN  
LEFT OUTER JOIN HEADING H12 ON L1.IRN = H12.IRN
WHERE RVP.DTE BETWEEN {?start_date} AND {?end_date}
AND BFS.CODE = N'IDALBY' AND ( ( 'ALL' IN {?location} ) OR (RVP.PLOC IN{?location}) OR( L1.LNK IN {?location}))
GROUP BY   
CASE WHEN LTP1.TYP = N'LINE' THEN
(CASE WHEN H1.HEAD IS NULL THEN N'None' ELSE H1.HEAD END) 
 ELSE    
(CASE WHEN H12.HEAD IS NULL THEN N'None' ELSE H12.HEAD END)  
END
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 28 Mar 2013 at 3:25am
Yes and no.  I wouldn't create the case statement as a Crystal function - it can't be used in the command.  However, a Command is just a SQL Select statement - any statement/function that is valid in a Select statement in your database is valid in a command.  So, instead of using a custom function as above, you can integrate the logic from the case statement into your Where clause - don't set any variables, just use the date filters.  It might look something like this:
 
Case '{?Date Type}' --note that you need the quotes here around the string!
  when 'CD' then LDTE = DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
  when 'CW' then LDTE BETWEEN dateadd(week, datediff(week, 0, (getdate())), 0) AND  dateadd(week, datediff(week, 0, (getdate())), 6)
...<etc>
end
 
If you can't use a case statement in a where clause (some databases don't allow it) you would do something like this:
 
Where
  (('{?Date Type}' = 'CD' and LDTE = DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0))
OR
  ('{?Date Type}' = 'CW' and LDTE BETWEEN dateadd(week, datediff(week, 0, (getdate())), 0) AND dateadd(week, datediff(week, 0, (getdate())), 6))
OR
...<rest of date logic>
)
...<rest of where logic>
 
Not the parentheses in red - these are required in order for the logic to work correctly.
 
-Dell
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 28 Mar 2013 at 9:02pm
Thanks Dell, I will have a look at this as advised.
 
JS
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 16 Apr 2013 at 4:53pm
Hi Dell,
 
I have tried, that the first option doesn't work for SQL server 2008 R2 where it always points "syntax error near '=' "; so I have used the second option that works. I tried to integrate the logic of second option into the original sql part of the where clause involvig dates, the following are running OK for one of the column of crosstab:
WHERE  (('{?break_type}' = 'CD' and LDTE = DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0))
OR
  ('{?break_type}' = 'CW' and LDTE BETWEEN dateadd(week, datediff(week, 0, (getdate())), 0) AND dateadd(week, datediff(week, 0, (getdate())), 6))
OR
  ('{?break_type}' = 'CM' and LDTE BETWEEN DATEADD(month, datediff(month, 0, (getdate())), 0) AND  convert(datetime, convert(varchar(10), getdate(), 101)))
OR
 ('{?break_type}'='CQ' and LDTE BETWEEN DATEADD(qq, DATEDIFF(qq,0,getdate()), 0) AND  dateadd(dd,-1,dateadd(qq,1,DATEADD(qq, DATEDIFF(qq,0,getdate()), 0))))
OR
('{?break_type}'='CY' and LDTE BETWEEN DATEADD(yy, DATEDIFF(yy,0,getdate()), 0) AND  DATEADD(year, DATEDIFF(year, -1, getdate()), -1))
OR
('{?break_type}'='CFY' and LDTE BETWEEN  cast('01-Jul-' + cast( case when datepart(mm,getdate()) in (7,8,9,10,11,12) then DATEPART(yy,getdate())
             else DATEPART(yy,getdate())-1
               end as varchar) as datetime) AND                       
                              cast('30-Jun-' + cast( case when datepart(mm,getdate()) in (6,7,8,9,10,11,12) then DATEPART(yy,getdate())
                else DATEPART(yy,getdate())+1
               end as varchar) as datetime))
OR
('{?break_type}'='PD' and LDTE = DATEADD(day, DATEDIFF(day, 0, GETDATE()), -1))
OR
('{?break_type}'='PW' and LDTE between DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0) and DATEADD(wk,DATEDIFF(wk,7,GETDATE()),6))
OR
('{?break_type}'='PM' and  LDTE between DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0) and
 DATEADD(DAY, -(DAY(GETDATE())), GETDATE()))
OR
('{?break_type}'='PQ' and LDTE between dateadd(quarter,datediff(quarter,0,getdate())-1,0) and DateAdd(day, -1, dateadd(qq, DateDiff(qq, 0, GETDATE()), 0)))
OR
('{?break_type}'='PFY' and LDTE  BETWEEN  cast('01-Jul-' + cast( case when datepart(mm,getdate()) in (7,8,9,10,11,12) then DATEPART(yy,getdate())
             else DATEPART(yy,getdate())-2
               end as varchar) as datetime) AND                       
                              cast('30-Jun-' + cast( case when datepart(mm,getdate()) in (6,7,8,9,10,11,12) then DATEPART(yy,getdate())
                else DATEPART(yy,getdate())-1
               end as varchar) as datetime))
OR
('{?break_type}'='PY' and LDTE between DATEADD(yy,-1,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)) and DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)))))
 
How do I code above  into another column where dates evaludated differently from above?
 
e.g. the another column:
 
SELECT   'Current Member' as Record_Type, 
CASE WHEN LTP1.TYP = N'LINE' THEN    
(CASE WHEN H1.HEAD IS NULL THEN N'None' ELSE H1.HEAD END)  
ELSE    
(CASE WHEN H12.HEAD IS NULL THEN N'None' ELSE H12.HEAD END)  
END,  COUNT(*)as Item_Count
FROM BDR  
INNER JOIN MAIN ON BDR.IRN = MAIN.IRN  
INNER JOIN BFS ON BDR.IRN = BFS.IRN  
LEFT OUTER JOIN BDB ON MAIN.IRN = BDB.IRN  
LEFT OUTER JOIN LOCLNK L1 ON BDB.LNK = L1.IRN  
LEFT OUTER JOIN LTP LTP1 ON BDB.LNK = LTP1.IRN  
LEFT OUTER JOIN HEADING H1 ON L1.LNK = H1.IRN  
LEFT OUTER JOIN HEADING H12 ON L1.IRN = H12.IRN  
WHERE (MAIN.CREATED_DATE <= {?end_date} AND (MAIN.DEACT_DATE IS NULL OR MAIN.DEACT_DATE > {?end_date}))
AND BFS.CODE = N'IDALBY' AND (  ( 'ALL' IN {?location}) OR( BDB.LNK IN {?location}) OR (L1.LNK IN {?location}))
GROUP BY   
CASE WHEN LTP1.TYP = N'LINE' THEN    
(CASE WHEN H1.HEAD IS NULL THEN N'None' ELSE H1.HEAD END)  
ELSE    
(CASE WHEN H12.HEAD IS NULL THEN N'None' ELSE H12.HEAD END)  
END
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 17 Apr 2013 at 5:32am
Assuming that this is MS-SQL.  I think you need single quotes around the parameters.
WHERE (MAIN.CREATED_DATE <= '{?end_date}' AND (MAIN.DEACT_DATE IS NULL OR MAIN.DEACT_DATE > '{?end_date}'))
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 29 Apr 2013 at 6:20pm
Hi,
 
I do not use  '{?end_date}'  to pass in parameters, but using break_type, e.g. date, week, month, quarter, so CW is current week, PW is previous week, etc.
When a user pick a break type, then the SQL in my post above doing the filter...
But I think when integrating the break type into the SQL, the logic is not working, the column of 'current members' in the cross-tab report disappears while the other columns still there; however the logic of
WHERE (MAIN.CREATED_DATE <= '{?end_date}' AND (MAIN.DEACT_DATE IS NULL OR MAIN.DEACT_DATE > '{?end_date}'))  works. So I don't know where it's incorrectly coded in the SQL part of my previous post using break_type. PLease further advise
J
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 30 Apr 2013 at 4:20am
It's very difficult to debug SQL from within Crystal.  So, I would try working with the SQL of the command in something like SQL Server Management Studio, using variables in place of the Crystal prompts and setting the value of the variable before running the Select.  Work with this until you have the SQL running correctly.  Then replace the variables with Crystal Prompts and paste the SQL (without the code for setting the variables) into Crystal.
 
-Dell
IP IP Logged
Page  of 2 Next >>
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