Solved

VBScript Coding Syntax with SQL query

Posted on 2009-05-13
5
437 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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 …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 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