Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 110
  • Last Modified:

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
0
AXISHK
Asked:
AXISHK
  • 3
  • 3
2 Solutions
 
MacroShadowCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aikimarkCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now