05-26-2015 04:50 PM
I have a PROC SQL that runs a Connection to Oracle. If I run this SQL statement in a SQL-specific program, the code runs just fine. However, I get an "Invalid SQL Statement" error when I run it in SAS.
In attempting to diagnose why, I copy/pasted the block of SQL from the SAS log and tried to run it that way, thinking the formatting of the code itself might have something to do with it. It looks like it does; when I run what the SAS log produces (I am assuming this is how SAS itself processes it), the SQL program produces the same error.
Is this an accurate conclusion? Also, if this is the case, is there a way to prevent that from happening?
05-27-2015 07:09 AM
I agree any code would be helpful, anytime you are passing through to any other environment there can be different nuances in how things should be written. Teradata case statements always throw me off.
05-27-2015 01:40 PM
The issue came in where I had multiple nested and/or statements in the WHERE clause. This is essentially what the statement in question looks like:
and((X.nbr_fld=123456 and X.dt_fld>='02-SEP-2014')
or (X.nbr_fld=234567 and X.dt_fld>='02-SEP-2014')
or (X.nbr_fld=345678 and X.dt_fld>='02-SEP-2014')
or (X.nbr_fld=111222 and X.dt_fld>='02-SEP-2014')
or (X.nbr_fld=222333 and X.dt_fld>='02-SEP-2014')
or (X.nbr_fld=123123 and X.dt_fld>='03-SEP-2014')
or (X.nbr_fld=321321 and X.dt_fld>='03-SEP-2014')
or (X.nbr_fld=432432 and X.dt_fld>='03-SEP-2014') ..... )
Because of the nature of the data I am working with, I have a number of these clauses (745, to be exact). Also, each date is particular to each serial number, so I am not sure if I could "hard code" any of these dates.
05-27-2015 03:19 PM
I got it! I was using pass-through logic already, so I looked further into the code to see if there was something I missed. Turns out there was.
The issue ended up being some commenting that I had in SQL using the "--" syntax. Since it seems SAS was processing the SQL statement as a block of text (instead of the line-by-line formatting I had), it was including some additional lines in the comment that I was not expecting. I took those parts out, and now it works just fine. Thank you Doc, Mark, and SASKiwi for helping me to get to the bottom of this!
Need further help from the community? Please ask a new question.