If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > ORDER BY Clause in SQL Statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-11-10, 23:00
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
ORDER BY Clause in SQL Statement

Hi Guys,

I'm getting stuck with the syntax on this one:

strSQL = "SELECT tblPaidAmounts.PaidID, tblPaidAmounts.PaidDate, tblPaidAmounts.Branch, " & _
"tblPaidAmounts.Collect, tblPaidAmounts.Discount, [collect]-[discount] AS AfterDiscount, " & _
"tblPaidAmounts.ExpAmt, [AfterDiscount]-[expamt] AS AfterExpenses, tblPaidAmounts.DepositAmount, [afterexpenses]-[depositamount] AS Balance " & _
"FROM tblPaidAmounts INNER JOIN tblbranches AS Branch ON branch.branchid = tblpaidamounts.branch " & _
"WHERE tblpaidamounts.Branch = " & Branchid
"ORDER BY paiddate DESC"

So Branchid is a global variable (I think) or it comes from a table when the user logs into the database, trouble is I can't encapsulate the branchid with a another & or use " & _ as I keep on getting unterminated string errors???
Reply With Quote
  #2 (permalink)  
Old 03-11-10, 23:05
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
OK before I get flamed, let me put in a brief explanation, I tried to delete this post but I couldn't.

I managed to sort it out, I should have put a space in between the quote marks.

So this one is correct:

strSQL = "SELECT tblPaidAmounts.PaidID, tblPaidAmounts.PaidDate, tblPaidAmounts.Branch, " & _
"tblPaidAmounts.Collect, tblPaidAmounts.Discount, [collect]-[discount] AS AfterDiscount, " & _
"tblPaidAmounts.ExpAmt, [AfterDiscount]-[expamt] AS AfterExpenses, tblPaidAmounts.DepositAmount, [afterexpenses]-[depositamount] AS Balance " & _
"FROM tblPaidAmounts INNER JOIN tblbranches AS Branch ON branch.branchid = tblpaidamounts.branch " & _
"WHERE tblpaidamounts.Branch = " & Branchid & " " & _
"ORDER BY paiddate DESC"

And then it works.

OK So flame away, sorry guys
Reply With Quote
  #3 (permalink)  
Old 03-12-10, 08:15
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,071
Response.Write()...
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On