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?
 
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.