Solved

VBScript Coding Syntax with SQL query

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now