Link to home
Start Free TrialLog in
Avatar of lavita
lavitaFlag for United States of America

asked on

CR2013 - SQL Query Command - Connecting to Dynamic Data Source (Excel .CSV Files)

Hi Experts,

Here's the situation: My company receives .csv files generated by an external system every day. The .csv files are named based on the date generated, i.e. '03-13-16.csv'. I've been asked to design a report in Crystal Reports 2013 that uses some of the data from these spreadsheets. Since this report will be most likely run on a daily basis, I need a way for Crystal Reports to accept a date parameter and query the appropriate .csv file. Is this possible? I spent all day experimenting with the SQL query command, and here's what I have that does work:

Two String Parameters:
CSVName - example of accepted value: `03-13-2016#csv` `03_13_2016_csv`
SheetName - example of accepted value: `03_13_2016_csv`
 
Query Statement:
 
SELECT
{?SheetName}.`START DATE`,
{?SheetName}.`START TIME`,
{?SheetName}.`END DATE`,
{?SheetName}.`END TIME`,
{?SheetName}.`TALK TIME`,
{?SheetName}.`CALL DURATION`,
{?SheetName}.`DIALED NUMBER`
 
FROM {?CSVName};

My issue is this:
1) Am I mistaken in thinking that these parameters will prompt the user for information each time the report is ran?

2) I do not want my coworkers to have to write in the file name in such an obtuse manner, i.e. `03-13-2016#csv` `03_13_2016_csv`, I would love if I could implement a date parameter, and then format that date as a string and concatenate it into the SELECT / FROM statement, as seen below:

New date parameter: GetDate

SELECT
'`' + FORMAT({?GetDate}, 'MM_DD_YYYY') + '_csv`'.`START DATE`,
'`' + FORMAT({?GetDate}, 'MM_DD_YYYY') + '_csv`'.`START TIME`,
'`' + FORMAT({?GetDate}, 'MM_DD_YYYY') + '_csv`'.`END DATE`,
'`' + FORMAT({?GetDate}, 'MM_DD_YYYY') + '_csv`'.`END TIME`,
'`' + FORMAT({?GetDate}, 'MM_DD_YYYY') + '_csv`'.`TALK TIME`,
'`' + FORMAT({?GetDate}, 'MM_DD_YYYY') + '_csv`'.`CALL DURATION`,
'`' + FORMAT({?GetDate}, 'MM_DD_YYYY') + '_csv`'.`DIALED NUMBER`
 
FROM '`' + FORMAT({?GetDate}, 'MM-DD-YYYY') + '#csv`' + ' ' +'`' + FORMAT({?GetDate}, 'MM_DD_YYYY') + '_csv`';
 
(The above FROM statement should be equal to the previous {?CSVName} parameter.)


But this gives me the error:
Error: 'DAO Error code 0xc03'
Description: "Invalid use of '.', '!', or '()'. in query expression '`' + FORMAT({?GetDate}, 'MM_DD_YYYY') + '_csv`'.`START DATE`"

Does anyone have any ideas? I'm new to SQL, but eager to learn and I really hope that this can be accomplished.

Thank you so much!
ASKER CERTIFIED SOLUTION
Avatar of vasto
vasto
Flag of United States of America image

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
SOLUTION
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
Avatar of lavita

ASKER

Vasto & mlmcc,

Thank you so much for assisting me. While it's disappointing that the data source can't be set dynamically, I'm glad to know that I can stop searching for ways to make it happen. :)

I'll look into other methods to organize the .csv file, thanks again!
Avatar of lavita

ASKER

Thank you!