Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORDER BY error?

Status
Not open for further replies.

danieljoo

MIS
Oct 9, 2002
43
0
0
US
Can you tell me what is wrong with my ORDER BY statement below. I get the following error "Missing semicolon (;) at end of SQL statement". Thanks.

MyVar1 = Request.Querystring("CustomerNumber")
MyVar2 = Request.Querystring("AttendeeFirstName")
MyVar3 = Request.QueryString("AttendeeLastName")
MyVar4 = Request.QueryString("Orderby")
strsql = "select * from Customer WHERE CUSTOMERNUMBER='" & myVar1 & "'"
set rs = Server.CreateObject("ADODB.Recordset")
If MyVar4 ="" then
sql = "update Attendee set Printed=TRUE WHERE CustomerNumber='" & myVar1 & "' and AttendeeFirstName='" & myVar2 & "' and AttendeeLastName='" & myVar3 & "'"
else
sql = "update Attendee set Printed=TRUE WHERE CustomerNumber='" & myVar1 & "' and AttendeeFirstName='" & myVar2 & "' and AttendeeLastName='" & myVar3 & "'"
sql = sql & " ORDER BY '" & MyVar4 & "'"
end if
conn.Execute (sql)
 
Try this:

sql = sql & " ORDER BY '" & MyVar4 & "';"

 
[ol]
[li]Why are you using an order by on an update?

[li]You shouldn't put single quotes around the column name in the order by clause. It should just be sql = sql & " ORDER BY " & MyVar4

[li]Where do you execute "strSQL"? You have 2 different query strings - what does the first string do?
[/ol]
-----------------------------------------------------------------
"Whether you think that you can, or that you can't, you are usually right."
- Henry Ford (1863-1947)

mikewolf@tst-us.com
 
I am using an Order by with the update becuase the page that gets updated has fields that can be ordered by. I don't want the order to change when the page gets updated. strsql is used to display the information for this page, while sql is used to update another page.

#2 didn't work either.
 
Just a thought as a last resort;

Put in a:

Response.Write sql
Response.end

Right before the execute statement. Save and Refresh the page. Then take the SQL code back to the database and manually run the query.

 
"the page that gets updated has fields that can be ordered by" - You are updating a database, right? Then using the new data to create another page that uses a select statement. I think that the order by clause only works on a SELECT statement... -----------------------------------------------------------------
"Whether you think that you can, or that you can't, you are usually right."
- Henry Ford (1863-1947)

mikewolf@tst-us.com
 
still no dice. Here is the output of the response.write (without the single quotes):

update Attendee set Printed=TRUE WHERE CustomerNumber='2' and AttendeeFirstName='Ellen' and AttendeeLastName='Mark' ORDER BY AttendeeCity
 
As far as I can remember from a million years ago in a Advanced Structure Query Language class [smile] the ORDER BY method is not valid in the UPDATE statement. ---------------------------------------
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }

 
What do you need another solution to? Are you trying to order your output on this page? Whereever the page, you want to make sure that you use your order by clause on the select statement for that page. I'm not exactly sure what you are trying to do.... -----------------------------------------------------------------
"Whether you think that you can, or that you can't, you are usually right."
- Henry Ford (1863-1947)

mikewolf@tst-us.com
 
..am using an Order by with the update becuase the page that gets updated has fields that can be ordered by. I don't want the order to change when the page gets updated.

WHAT?
I recommend any good book on SQL before you go any further. Stored orders of records in a database are not influenced by any sql statement except one that creates a clustered index such as a primary key. The basic question is why do you care how they ordered in a database. When you want order, specify an ORDER in a select statement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top