String size in Excel VBA

I have a string that contains a long SQL structure for retrieving data from SQL Server. Is there a work around solution to have longer string size to contain this long statement ?

Tks
AXISHKAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MacroShadowConnect With a Mentor Commented:
Use line continuations to split your statement into multiple lines. i.e.
strSQL = "Use line continuations" _
         & "to split your statement" _
         & "into multiple lines"

Open in new window

0
 
AXISHKAuthor Commented:
Seem like there is a size limitation in string strSQL, correct ?
0
 
MacroShadowCommented:
About 2 billion characters. I seriously doubt you're even close to that limit.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
aikimarkConnect With a Mentor Commented:
There is a limit on the number of lines that can be continued

You may have to use string concatenation.
Example:
strSQL = "Select * "
strSQL = strSQL & "From mytable "
strSQL = strSQL & "Where fieldname = 42"

Open in new window


You could also read the SQL string from a file source.

================
Are you trying to store the SQL in an Excel cell?
0
 
AXISHKAuthor Commented:
The SQL statement is coded in a VBA. Any better way to handle this ?

For string size, it is not limited to 255 chars, correct ?

Tks
0
 
MacroShadowCommented:
Coding the string in VBA is fine as long as the lines are not too long (use line continuations or string concatenation).
String size isn't limited to 255 chars.
0
 
AXISHKAuthor Commented:
Tks
0
All Courses

From novice to tech pro — start learning today.