2 Replies - 783 Views - Last Post: 02 November 2012 - 09:50 AM Rate Topic: -----

#1 synlight  Icon User is offline

  • D.I.C Addict

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

ORDER BY clause not working

Posted 02 November 2012 - 09:34 AM

Hi all! I am working on a homework assignment. I have the majority of it done, but my ORDER BY clause is throwing an error. If I take the clause out, it runs fine, and I can't figure out why. I'm thinking there is a rule I am forgetting, but I have looked through my book and can't find anything.

USE AP
DECLARE @BalanceDue money
SET @BalanceDue = (SELECT SUM(InvoiceTotal-PaymentTotal-CreditTotal) FROM Invoices)
IF @BalanceDue > 10000
	(SELECT VendorName, InvoiceNumber, InvoiceDueDate, InvoiceTotal-PaymentTotal-CreditTotal AS BalanceDue
	 FROM Invoices JOIN Vendors
	 ON Invoices.VendorID = Vendors.VendorID
	 WHERE InvoiceTotal-PaymentTotal-CreditTotal > 0
	 ORDER BY InvoiceDueDate DESC)
ELSE
	PRINT 'Balance due is less than $10000'


Is This A Good Question/Topic? 0
  • +

Replies To: ORDER BY clause not working

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9572
  • View blog
  • Posts: 36,247
  • Joined: 12-June 08

Re: ORDER BY clause not working

Posted 02 November 2012 - 09:41 AM

Is this MSSQL or MYSQL? If the former then double check your if statements.. instead of ( and ) it is BEGIN and END.

http://msdn.microsof...7(SQL.105).aspx
Was This Post Helpful? 1
  • +
  • -

#3 synlight  Icon User is offline

  • D.I.C Addict

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: ORDER BY clause not working

Posted 02 November 2012 - 09:50 AM

View Postmodi123_1, on 02 November 2012 - 11:41 AM, said:

Is this MSSQL or MYSQL? If the former then double check your if statements.. instead of ( and ) it is BEGIN and END.

http://msdn.microsof...7(SQL.105).aspx



It's MSSQL.. Thanks for the link Modi, works great now!

This post has been edited by synlight: 02 November 2012 - 09:52 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1