All Forums >> [Scripting] >> ASP >> Interpreting Statements in ASP Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Posts: 9
Score: 0
Joined: 6/9/2001
From: USA
Status: offline
I have a SELECT statement that needs to select 3 fields from a table:
Grace="SELECT Date1, Date2, 'Consumed' Status" & _ "FROM Table1 WHERE Upper(UserID)='" & UserIDGrace & "'" Grace=Grace & "Order By Status DESC, Date1 ASC"
1. Why will my ASP page display 'Consumed' under 1 of the fields on in the table displayed when <'Consumed' Status"> is not a field in Table1? What does <Upper(UserID)> do? 2. What are the <& _> behind <'Consumed' Status"> used for? 3. Why is UserIDGrace enclosed in <'" & & "'>? 4. What is DESC and ASC used for? 5. What is 'wend' used for? is it used to end the program?
Posts: 11
Score: 0
Joined: 5/22/2001
From: USA
Status: offline
In rough order;
1. Where you have 'Consumed' Status, your database is probably interpreting this as a user-defined field. By entering 'Consumed' Status, you're basically saying "display a column called Status and enter 'Consumed' as its value".
For example, "select 'Andy' as Name" will display a column called name and fill in the value 'Andy'.
Upper converts the value you pass to it to upper-case, usually for case-sensitive comparison purposes. So, Upper('andy') returns 'ANDY'.
2. & is used by VBScript/VB/VBA to concatenate a string; that is "My" & "String" becomes "MyString". Be careful not to mix up & and + and check your database documentation for the differences between concatentation and addition operators, otherwise you might get some funny results.
3. The statement you're building is a string that will probably be passed to a database to execute, hence the & operators. The underscore means "continue on this line" and is just a way of breaking a single statement down onto multiple lines.
So;
statement1 _ statement2 _ statement3
is the same as statement1 statement2 statement3
4. DESC is SQL for "order this field in descending order" - ASC I assume means ascending, though this is the default and I've never seen it used before.
5. This is VBScript/VB/VBA for "end a while conditional loop" - it needs to accompany a While statement;
for example;
While (Not rs.EOF) ' do statements rs.MoveNext WEnd