Syntax Error from VBA/SQL use of Like - sql

I've got a sql command in vba (access 2007) that's giving me errors, and I don't know why. Specifically, it says that there's a missing operator in the WHERE clause. I can't figure out what is missing. It's not the UDF ReplaceNotAN, which replaces the specific non-alphanumeric characters.
Any ideas for what's going on, and how to fix it? Everything I could find for similar error on the intertubez is irrelevant (mostly about the single vs double quotes issue - but clearly that doesn't apply here).
dcSql = "UPDATE table SET table.Customer=ReplaceNotAN(Customer)" & _
" WHERE table.Customer Like '*[-,.;:_'&=\/#]*';"
DoCmd.RunSQL dcSql

you have an additional single quote in the like phrase...
try it by doubling that one i think...
Like '*[-,.;:_''&=\/#]*';"

Related

Teradata SQL - Replacing special characters

I'm using Report Builder 3.0 for my reports. My report runs, however, if a user exports the results to Excel (xlsx) instead of Excel 2003 (xls), they get an "illegal xml character" message when the file is open.
4 of the columns contain "&" and / or " ' "; so I'm trying to replace these special characters; which I believe are causing the issue.
I've tried to update this line:
j.journal_desc AS "Jrnl Description",
with this line:
oreplace(oreplace(j.journal_desc, ’&’, β€˜and’),'''','') AS "Jrnl Description",
and it works fine. However when I do this on a second line I get the message: "SELECT Failed. [9804] Response Row size or Constant Row size overflow".
I've tried "otranslate" and it works on 2 columns. However, when I try it on the 3rd column, I get the same overflow message.
Is it possible to use oreplace or otranslate on multiple columns? Am I doing something wrong? Is there a better way to replace these special characters? t
Thanks for the help......
oreplace and otranslate when used the result string will have length of 8000 unicode characterset.each of otranslate will make much longer by 8000. Try to cast to smaller length should fix problem.
CAST(oreplace(journal_desc,'&','and') AS VARCHAR(100))

SAS - how to mask double quotes (e.g. "")

I am running a VBA program from SAS. The SAS code for this basically looks like:
%let worksheet =&i; *worksheet number;
%let xlsfile = %STR(""C:\Data\Excel Workbook.xlsx"");
%let csvfile = %STR(""C:\Data\CSV File..csv"");
x 'cd "C:\Data\MN2013\Alignment\Data\SAS Programs"';
x "XlsWsToCsv.vbs &xlsfile &worksheet &csvfile";
I need to be able to include two double quotes (i.e. "") at the beginning and end of the file paths in the xlsfile and csvfile for the VBA program to recognize the spaces in the file paths and run correctly.
MY PROBLEM:
I run this in SAS Enterprise Guide using SAS 9.3. In my log, directly after the variable definition is read in, the double quotes are underlined in red (usually indicating an error) with the number 49 below. There is no error message, but instead, in green I get the following note:
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS
release. Inserting white space between a quoted string and the succeeding
identifier is recommended.
To me, this says SAS is reading these double quotes. They are somehow only partially being masked. My VBA program runs, so I could continue with this; but I like clean error logs. Does anyone have any recommendations for how to completely mask my xlsfile and csvfile variables? I've tried using %STR (as shown in my example above), %BQUOTE, %SUPERQ, and a few other things to make this work.
Those pesky error messages! You were very close, but try this syntax instead:
%let xlsfile = %STR("")C:\Data\Excel Workbook.xlsx%STR("");
%let csvfile = %STR("")C:\Data\CSV File..csv%STR("");
Double double quotes inside double quotes resolve to a single double quote character, ie...
x """c:\program files\office\excel.exe"" stuff stuff stuff ""stuff"" stuff";
should work just fine. Don't worry about the 'identifier' message, that's largely saying something like
"01JAN2013"d
could be possible with other things. You can add a space after the last " if it's a problem to have that in the log.

Why am I getting "ORA-00923: FROM keyword not found where expected"?

Why is the "From" seen as being in the wrong spot?
I had to change double quotes to single quotes in a query to get the query string to compile in the IDE while porting from Delphi to C#.
IOW, with SQL like this, that works in Delphi and Toad:
#"SELECT R.INTERLOPERABCID "ABCID",R.INTERLOPERID "CRID", . . .
...I had to change it to this for it to compile in Visual Studio:
#"SELECT R.INTERLOPERABCID 'ABCID',R.INTERLOPERID 'CRID', . . .
However, the SQL won't run that way - I get the "ORA-00923: FROM keyword not found where expected" err msg (both in Toad and when trying to execute the SQL in the C# app).
How can I get it both to compile and to run?
The quotes around your column aliases are giving it heartburn.
It appears that in the original case, the entire query is surrounded by double quotes, and the double quotes around the column aliases mess with those.
In the second case, Oracle is interpreting the single-quoted column aliases as strings, which throw it off.
In Oracle, you shouldn't need either: You should be able to just code:
#"SELECT R.INTERLOPERABCID ABCID,R.INTERLOPERID CRID, . . .
or, using the optional AS keyword:
#"SELECT R.INTERLOPERABCID AS ABCID,R.INTERLOPERID AS CRID, . . .
Hope this helps.
It is generally don't work if you have inline comments in query

DataTable.Select with ' (single quote) Character in the query vb.net

I have a string like "Hello'World" and a DataTable with some records in it. One of those records is "Hello'World".
The problem is, when I do a .Select in the DataTable, it only tries to search for the "Hello" part and throws an error on "World" because it interprets the ' (single quote) like the closing quote on sql.
DataTable.Select("text = 'Hello'World'")
I have gone through msdn doc, and it says I can escape some characters with [] brackets or f.slashes \, but I just can't figure out: .select("text = 'Hello[']world'")
I've done some reading: Verbatim in vb - c# and "jmcilhinney" explains it really well. BUT, it did not answer my question for what I want to do. In stackoverflow.com, a same question is posted but in c#, but I can't find a way to use # in vb.
Can you please redirect me to more doc, examples or any one of you have ever encountered this problem?
Use '' (this is 2 ' characters).
DataTable.select("text = 'Hello''World'")

vb.net VB 2010 Underscore and small rectangles in string outputs?

I've made some good progress with my first attempt at a program, but have hit another road block. I'm taking standard output (as a string) froma console CMD window (results of dsquery piped to dsget) and have found small rectangles in the output. I tried using Regex to clean the little bastards but it seems they are related to the _ (underscore), which I need to keep (to return 2000/NT logins). Odd thing is - when I copy the caharcter and paste it into VS2K10 Express it acts like a carrige return??
Any ideas on finding out what these little SOB's are -- and how to remove them?
Going to try using /U or /A CMD switch next..
The square is often just used whenever a character is not displayable. The character could very well be a CR. You can use a Regular Expression to just get normal characters or remove the CR LF characters using string.replace.
You mentioned that you are using the string.replace function, and I am wondering if you are replacing the wrong character or something like that. If all your trying to do is remove a carriage return I would skip the regular expressions and stick with the string.replace.
Something like this should work...
strInputString = strInputString.replace(chr(13), "")
If not could you post a line or two of code.
On a side note, this might give some other examples....
Character replacement in strings in VB.NET