Sorting in sql string

TanMan

Registered User.
Local time
Today, 01:33
Joined
Oct 15, 2010
Messages
16
Need to sort by the Product name, what is the syntax:banghead:

"WHERE fkProdType = " & cboProductTypeLookup & " And " & "tblProduct.discontinued = 0" & ""

Thanks for the help
 
Try

Code:
SqlStr="SELECT * 
FROM tblProduct 
WHERE fkProdType = " & cboProductTypeLookup & " And tblProduct.discontinued = 0 
ORDER BY tblProduct.[Product Name]"

Note if cboProductTypeLookup is text rather than numeric then the WHERE line needs to be (note the addition of single quotes):
Code:
WHERE fkProdType = '" & cboProductTypeLookup & "'
 
Quick Examples:
Select Field1, Field2 from Table where X=3 order by Field2 ASC
Select Field1, Field2 from Table where X=3 order by Field2 DESC
Select Field1, Field2 from Table where X=3 order by Field2 DESC, Field3 ASC

ASC means ascending order, DESC means descending order
 
I am getting an (expected: end of statement) error at

Order By tblProduct.[Product Name]

tblProduct is highlighted
 
I am getting an (expected: end of statement) error at

Order By tblProduct.[Product Name]

tblProduct is highlighted


The ORDER BY Statement looks correct, but it is difficult to determine the issue out of context, since there could be a problem with the way you are trying to use it in your SQL Statement. Two quick things to look for include:
  • If you add an ORDER BY Statement to a Query that already has a ";", it needs to be added before the ";"
  • There needs to be a space in front of the ORDER BY Statement as well.
If neither of those suggestions helps out, then show us the whole updated SQL Statement, and perhaps we can come up with some other ideas.

-- Rookie
 
If you are unfamiliar with SQL syntax, start with the QBE and do as much as you can by clicking and dragging. You can then switch to SQL view for final tweaking if need be.
 

Users who are viewing this thread

Back
Top Bottom