Solved

VBScript Coding Syntax with SQL query

Posted on 2009-05-13
5
429 Views
Last Modified: 2012-05-06
(Code1 Question) Am using   file.write line   to create row header to output results of sql query to  csv file.
 In the code,  I need to separate the line for readability. Or can I use a str variable instead? How would I do that?

(Code2 Question) Am using     SQL=SQL &    to separate sql query in VBScript. Can I use a str variable instead? How would I do that?

'Code1 Sample:
file.WriteLine ""CLASS"",""SCHOOLNUM"",""SCHLNAME"",""SECTION"",""COURSE"",""TITLE"" "
'would like to separate it: into 2 lines or use a variable. (such as strheader=?)
 
'Code2 Sample:
SQL="select blah, blah, blah, blah....."
SQL=SQL & "blah, blah, blah....."
Can I use  a variable instead? (such as strsql=?)

Open in new window

0
Comment
Question by:lbarnett419
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24375190
First question, to seperate into two lines, can you not just do two write lines?
file.WriteLine ""CLASS"",""SCHOOLNUM"",""SCHLNAME"","
file.WriteLine"SECTION"",""COURSE"",""TITLE"" "


SQL is already a variable!

 
'Code2 Sample:
SQL="select blah, blah, blah, blah....."
SQL=SQL & "blah, blah, blah....."
Can I use  a variable instead? (such as strsql=?)
0
 

Author Comment

by:lbarnett419
ID: 24375550
(1) Will separating into file.writeline 2x keep the entire row intact in the file?

(2) I understand about #2, but can't I declare
strsql="Select blah, blah, blah from table"    
 then use the strsql instead of all the lines of SQL=SQL& I would need with a big query?

Be patient with me; I'm a novice in this area. Thanks
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24375805
(1) Ok, you mean in code you want to write in two lines but show as one line when written?

use .write instead of .writeline

file.write

then end with

file.writeline

(2) Do you mean you want to append a string?
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24375856
String concatenation can be done using & as you have done

strsql = "xxxx"
strsql = strsql & "yyyy"


Regarding (1)

And example

I use chr(34) to write a double quote

f.Write chr(34) & "CLASS" & chr(34) & "," & chr(34) & "SCHOOLNUM" & chr(34) & "," & 

chr(34)
f.write "SCHLNAME" & chr(34) & "," & "SECTION" & chr(34) & "," & chr(34)
f.writeline "COURSE" & chr(34) & "," & chr(34) & "TITLE"
0
 

Author Closing Comment

by:lbarnett419
ID: 31580982
Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question