Solved

VBScript Coding Syntax with SQL query

Posted on 2009-05-13
5
435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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