Jim Horn
asked on
Looking for a damn-handy SQL parser in VBA
Does anyone have any code from a prior project that edits SQL statements?
------
I have a graph that's table-driven, where one of the fields is the SQL string. An example is...
SELECT tbl_time.txt_time_month_ye ar AS [Month], tbl_indicators_data.sng_id ata_value_ 1 AS [ALCOA]
FROM tbl_time INNER JOIN tbl_indicators_data ON tbl_time.lng_id = tbl_indicators_data.lng_mo nth_id
WHERE tbl_indicators_data.lng_in dicator_id = 32
ORDER BY tbl_time.lng_month_ID ASC;
The above SQL displays a graph with all values.
I have a business need to allow the user to edit the above to allow FROM and TO dates, like (note the WHERE-BETWEEN CLAUSE)...
SELECT tbl_time.txt_time_month_ye ar AS [Month], tbl_indicators_data.sng_id ata_value_ 1 AS [ALCOA]
FROM tbl_time INNER JOIN tbl_indicators_data ON tbl_time.lng_id = tbl_indicators_data.lng_mo nth_id
WHERE tbl_indicators_data.lng_in dicator_id = 32 AND tbl_time.lng_month_ID BETWEEN 200201 AND 200312
ORDER BY tbl_time.lng_month_ID ASC;
I can hack the big components of SQL okay, but getting the 'AND tbl_time.lng_month_ID BETWEEN 200201 AND 200312' clause is proving to be a pain.
Points given generously for anything I can build on.
TIA -Jim
------
I have a graph that's table-driven, where one of the fields is the SQL string. An example is...
SELECT tbl_time.txt_time_month_ye
FROM tbl_time INNER JOIN tbl_indicators_data ON tbl_time.lng_id = tbl_indicators_data.lng_mo
WHERE tbl_indicators_data.lng_in
ORDER BY tbl_time.lng_month_ID ASC;
The above SQL displays a graph with all values.
I have a business need to allow the user to edit the above to allow FROM and TO dates, like (note the WHERE-BETWEEN CLAUSE)...
SELECT tbl_time.txt_time_month_ye
FROM tbl_time INNER JOIN tbl_indicators_data ON tbl_time.lng_id = tbl_indicators_data.lng_mo
WHERE tbl_indicators_data.lng_in
ORDER BY tbl_time.lng_month_ID ASC;
I can hack the big components of SQL okay, but getting the 'AND tbl_time.lng_month_ID BETWEEN 200201 AND 200312' clause is proving to be a pain.
Points given generously for anything I can build on.
TIA -Jim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Resolved it by re-writing the entire WHERE clause every time, instead of trying to hack multiple WHERE critera.
Wow. <sniff> You were the only one that cared...
Wow. <sniff> You were the only one that cared...
You should have asked an easier question, like "How do I make my form go beep"...:-)
Still not entirely sure why you're dynamically change the WHERE clause though - there must be an easier way?
Still not entirely sure why you're dynamically change the WHERE clause though - there must be an easier way?
ASKER
Don't tempt me... if there's a mad push for points, I can ask all sorts of silly questions...
ASKER
(2) In SQL code I'm reading the data, populating FROM and TO combobox.rowsources, and displaying the first and last months as the values.
Pretty damn slick if I do say so myself.
My problem is, every time I alter the SQL I need to read the existing SQL, determine if there's an existing BETWEEN clause (somewhat tough), if so wipe it out, and write a replacement (fairly easy).
Perhaps I'll include the BETWEEN clause in every SQL statement, even if it's redundant, just to make user changes like this easier.