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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Order by' problem

Status
Not open for further replies.

wuah

Programmer
Mar 15, 2001
42
DK
Hello

I have the following sql-statement:

strSQL = "SELECT * FROM tblCBtest WHERE ((cb = '" & strTypen1 & "') OR (cb2 = '" & strTypen2 & "') OR (cb3 = '" & strTypen3 & "')) AND "
strSQL = strSQL & " (Amt LIKE '%" & strAmt & "%') AND "
strSQL = strSQL & " (Postnr LIKE '%" & strPostnr & "%') AND "
strSQL = strSQL & " (Byen LIKE '%" & strByen & "%') AND "
strSQL = strSQL & " (Navn LIKE '%" & strNavn & "%')"


My problem is that i want to order the output by "Navn".

Where do I put my "ORDER BY Navn" command.
I've tried to place it at the end of the SQL, but that doesn't seem to work..

What do I do wrong?

Help please

Greetings Rasmus
 
The Order By is placed at the end of the statement. Is the statement not executing or not ordering the data?

 
Did you remember to leave a space after the last section of the WHERE clause. Try writing to the SQL command to the screen to make sure that it looks OK. Mise Le Meas,

Mighty :)
 
Thanks for the answers...

The problem was caused by a personal blunder blunder by myself. It's going in the end of the statement but i forgot to put it inside the sql.
Sometimes you just see yourself blind on something when it's right in front of you face - but thanks anyway!

This is what caused the problem:

strSQL = "SELECT * FROM tblCBtest WHERE ((cb = '" & strTypen1 & "') OR (cb2 = '" & strTypen2 & "') OR (cb3 = '" & strTypen3 & "')) AND "
strSQL = strSQL & " (Amt LIKE '%" & strAmt & "%') AND "
strSQL = strSQL & " (Postnr LIKE '%" & strPostnr & "%') AND "
strSQL = strSQL & " (Byen LIKE '%" & strByen & "%') AND "
strSQL = strSQL & " (Navn LIKE '%" & strNavn & "%')"
ORDER BY navn ASC "
========================

This is the right way - simple [sigh]:

strSQL = "SELECT * FROM tblCBtest WHERE ((cb = '" & strTypen1 & "') OR (cb2 = '" & strTypen2 & "') OR (cb3 = '" & strTypen3 & "')) AND "
strSQL = strSQL & " (Amt LIKE '%" & strAmt & "%') AND "
strSQL = strSQL & " (Postnr LIKE '%" & strPostnr & "%') AND "
strSQL = strSQL & " (Byen LIKE '%" & strByen & "%') AND "
strSQL = strSQL & " (Navn LIKE '%" & strNavn & "%') ORDER BY navn ASC"


- my bad ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top