I have got a string containing "&" like "Coke & Cola" How to use this string on Queries with & Please Help me.
I must Query by this sign &
Have you tried using
amp;
or
\&
?
I'm making the assumption that you're using Sharepoint given the tag - I found an article here that might be relevant to your problem:
http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomizationlegacy/thread/90479143-e26e-45cc-ae56-16574056d6d4
[general SQL] There are many answers take a look at source link:
SET ESCAPE ON
SET ESCAPE ""
SELECT 'You & me' FROM DUAL;
source
[CAML SharePoint] answer:
replace & with &
& must be changed to &
Also <must be changed to < and >must be changed to >
Related
I have a macro that prompts me for a SQL query (unless it was called by another Sub, in which case it uses the argument that was passed into its optional string parameter as the query) and then executes the query against my Teradata SQL database.
It works fine, unless there's a column alias containing a space in the query.
Example query:
SELECT 2 + 2 AS "Query Result";
Error:
Run-time error '1004':
[Expression.Error] The name 'Source' wasn't recognized. Make sure it's spelled correctly.
The line of code which I believe is the culprit is as follows (my apologies for the readability-- I recorded the macro, modified it just enough to get it to work somewhat dynamically and then haven't touched it since).
ActiveWorkbook.Queries.Add Name:=queryName, formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Odbc.Query(""dsn=my-server-name"", " & Chr(34) & code & Chr(34) & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Source"
I assume it has to do with the fact that the example query above has double quotes for the alias, which are confusing the syntax when trying to be interpolated. Any help would be greatly appreciated!
Here's what the string for the formula is set to in this line:
ActiveWorkbook.Queries.Add Name:=queryName, formula:=<string here>
after all the chr() and concatenation are done:
let
Source = Odbc.Query("dsn=my-server-name", "<code>")
in
Source
That token <code> is replaced by whatever is in your variable code. So I suspect you are correct in that this formula would need to have it's double quotes escaped fully.
In other words this string you are building form Formula is going to be evaluated as code itself, and even in that evaluation it will be passing more code (your SQL) onto the Teradata server to be evaluated there.
You are in code inception. VBA code writing powerquery code writing Teradata code.
Understanding that and guessing a bit here, I'm thinking your current code variable looks something like:
code="SELECT 2 + 2 AS ""Query Result"";"
Your double quotes are already escaped for VBA. BUT because you have to survive another round of eval in powerquery you need to escape once again. Instead:
code="SELECT 2 + 2 AS """"Query Result"""";"
*I think...
This is my code,
Set T = .Find("Goal Progress - As per Academy", lookat:=xlWhole)
I couldn't find this column as it has "-" in the middle. Could someone help me, please?
Try using this
Set T = .Find("Goal Progress " & ChrW(45) & " As per Academy", lookat:=xlWhole)
the Special Characters you want to add to a string witch you cant type it like " you can Add it by it's code like following
ChrW()(45) = - (hyphen)
you can find more here
In lotus notes i have a script agent that auto generate mails and send it.
In the body of these mails i put lots of data among which some telephone numbers that i want they will be clickable from devices. How can i do this ?
Here the code that i use:
notebody="People:" & doc.people(0) & chr(10) & Cstr(doc.date(0)) & "Phone Number:"& doc.phone(0)
Set rtItem = New NotesRichTextItem(Maildoc , "Body" )
Call rtItem.AppendText(notebody)
The field that i want will be clickable is doc.phone(0). How can i do ? thank's
'First, see here: Answer to 'Is there a way to make a phone number clickable...'
In order to adapt that answer to a Notes agent that is using the rich text classes to generate a message, you would need to use pass-thru HTML. You can do this simply by surrounding the HTML fragment with '[' and ']' characters.
I.e., something like this:
notebody="People:" & doc.people(0) & chr(10) & Cstr(doc.date(0)) & |Phone Number: [| & doc.phone(0) & "]"
Note: not tested! I used the | char as the alternate for quotation marks in order to avoid escaping, and I checked carefully for typos, but...
I am trying to create a range in a function but the range varies so I am going to pass in the definition as a string but I am running into an error because it says it "Expected an array". So, I thought this was because the double quotes weren't included so I tried to include them in the string by doubling up on double quotes but now VBA is saying I have an invalid character in that string (that being the first dollar sign). I am really confused on how to fix this. Any help would be greatly appreciated.
gRange = ""$A$1:$F$2""
Whenever I have issues in VBA with extra quotes in strings, I always fall back on using Chr(34) to replace.
gRange = Chr(34) & "$A$1:$F$2" & Chr(34)
Chr() MSDN Reference
I found a solution using an if Statement like so:
If sheetName = "Totals" Then
ChartData.ActiveSheet.ListObjects("Table1").Resize Range("$A$1:$F$2")
Else
ChartData.ActiveSheet.ListObjects("Table1").Resize Range("$A$1:$G$2")
End If
Instead of using a string.
I just have to ask this for once...
Is there a more elegant way of having your output comma-delimited, than the tried and tested & "," & we always use?
print #myTextFileNumber, myValue1 & "," & myText2 & "," & myValue3
the command you are looking for is write
from the help:
the Write # statement inserts commas between items and quotation marks around strings as they are written to the file
in your example, then command would be:
write #myTextFileNumber, myValue1 , myText2 , myValue3
If you store your values in an array, you can use join.