473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Order by INSTR, urgent !

MemberID VID
1002 1001
1003 1002
1004 1003
1005 1003
1007 1001
1012 1002

<%
MemberList = "1001, 1003, 1002"
' The arrangement should not be changed....., the memberID and VID is number
format

SQL = "Select * From Member Where VID In (" & MemberList & ")"
SQL = SQL & " ORDER BY INSTR(""" & MemberList & """, VID)"
Set rs = GetMdbRecordset( "Member.mdb", SQL)

While not rs.eof
A = rs("MemberID")
Response.write A
rs.movenext
Wend
A = rs("memberID")
Response.write A
%>

The results come out is
MemberID VID
1007 1001
1002 1001
1005 1003
1004 1003
1012 1002
1003 1002

The MemberID of each VID always sort from the bottom, for example, 1003 get
1005 first, and then 1004....., I try the following but no hope :
SQL = SQL & " ORDER BY INSTR("" & MemberList & "", VID)"
SQL = SQL & " ORDER BY INSTR("" & MemberList & "", "MemberID)"
Also I try to change the MemberID to text format, eg: '1001', '1002', ......
It still "Bottom First Top Last", the result I want is as below :

MemberID VID
1002 1001
1007 1001
1004 1003
1005 1003
1003 1002
1012 1002

Please Help me how to fix it, Thanks a lot !
Jan 22 '06 #1
3 2582
Not sure I understand what you're asking, but maybe ...
SQL = "Select * From Member Where VID In (" & MemberList & ")"
SQL = SQL & " ORDER BY INSTR(""" & MemberList & """, VID), MemberID"

Bob Lehmann

"Mary" <al**@neind.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
MemberID VID
1002 1001
1003 1002
1004 1003
1005 1003
1007 1001
1012 1002

<%
MemberList = "1001, 1003, 1002"
' The arrangement should not be changed....., the memberID and VID is number format

SQL = "Select * From Member Where VID In (" & MemberList & ")"
SQL = SQL & " ORDER BY INSTR(""" & MemberList & """, VID)"
Set rs = GetMdbRecordset( "Member.mdb", SQL)

While not rs.eof
A = rs("MemberID")
Response.write A
rs.movenext
Wend
A = rs("memberID")
Response.write A
%>

The results come out is
MemberID VID
1007 1001
1002 1001
1005 1003
1004 1003
1012 1002
1003 1002

The MemberID of each VID always sort from the bottom, for example, 1003 get 1005 first, and then 1004....., I try the following but no hope :
SQL = SQL & " ORDER BY INSTR("" & MemberList & "", VID)"
SQL = SQL & " ORDER BY INSTR("" & MemberList & "", "MemberID)"
Also I try to change the MemberID to text format, eg: '1001', '1002', ....... It still "Bottom First Top Last", the result I want is as below :

MemberID VID
1002 1001
1007 1001
1004 1003
1005 1003
1003 1002
1012 1002

Please Help me how to fix it, Thanks a lot !

Jan 22 '06 #2
Mary wrote:
MemberID VID
1002 1001
1003 1002
1004 1003
1005 1003
1007 1001
1012 1002

<%
MemberList = "1001, 1003, 1002"
' The arrangement should not be changed....., the memberID and VID is
number format

SQL = "Select * From Member Where VID In (" & MemberList & ")"
SQL = SQL & " ORDER BY INSTR(""" & MemberList & """, VID)"
Set rs = GetMdbRecordset( "Member.mdb", SQL)


Bob has given you your immediate solution, but I just wanted to throw in
this caveat: add this record to the table and try your query using
MemberList="1001,1003,1002,100":

MemberId VID
1021 100

To fix this, you need to remove the spaces from MemberList, add commas to
the beginning and end of it in the InStr call, as well as putting commas
around VID:

MemberList = "1001, 1003, 1002, 100"
MemberList = Replace(MemberList," ","")
SQL = "Select * From Member Where VID In (" & MemberList & ")"
SQL = SQL & " ORDER BY INSTR(""" & "," & _
MemberList & ",', ',' & VID &','), MemberID"

If you Response.Write SQL, you should see

Select * From Member Where VID In (1001,1003,1002,100) ORDER BY
INSTR(',1001,1003,1002,100,', ',' & VID & ','), MemberID

You should be able to open your database in Access, create a new query in
Design view, switch to SQL View, paste the above sql statement in and run it
to see if it gives you the results you want.

You should always test your queries in Access before attempting to run them
from a client application such as ASP. This will allow you to catch
performance issues early in the process, as well as getting the benefit of
the more informative error messages that Access displays when you've done
somehthing wrong.

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jan 23 '06 #3
Dear Bob :
It work ! You solve my problem, thanks a lot.....
"Bob Lehmann" <no****@dontbotherme.zzz> ¼¶¼g©ó¶l¥ó·s»D:ej**************@TK2MSFTNGP14.phx.g bl...
Not sure I understand what you're asking, but maybe ...
SQL = "Select * From Member Where VID In (" & MemberList & ")"
SQL = SQL & " ORDER BY INSTR(""" & MemberList & """, VID), MemberID"

Bob Lehmann

"Mary" <al**@neind.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
MemberID VID
1002 1001
1003 1002
1004 1003
1005 1003
1007 1001
1012 1002

<%
MemberList = "1001, 1003, 1002"
' The arrangement should not be changed....., the memberID and VID is

number
format

SQL = "Select * From Member Where VID In (" & MemberList & ")"
SQL = SQL & " ORDER BY INSTR(""" & MemberList & """, VID)"
Set rs = GetMdbRecordset( "Member.mdb", SQL)

While not rs.eof
A = rs("MemberID")
Response.write A
rs.movenext
Wend
A = rs("memberID")
Response.write A
%>

The results come out is
MemberID VID
1007 1001
1002 1001
1005 1003
1004 1003
1012 1002
1003 1002

The MemberID of each VID always sort from the bottom, for example, 1003

get
1005 first, and then 1004....., I try the following but no hope :
SQL = SQL & " ORDER BY INSTR("" & MemberList & "", VID)"
SQL = SQL & " ORDER BY INSTR("" & MemberList & "", "MemberID)"
Also I try to change the MemberID to text format, eg: '1001', '1002',

......
It still "Bottom First Top Last", the result I want is as below :

MemberID VID
1002 1001
1007 1001
1004 1003
1005 1003
1003 1002
1012 1002

Please Help me how to fix it, Thanks a lot !


Jan 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: DTB | last post by:
I am trying to convert a complex function from Oracle to SQL Server and have come across Oracle's Instr() function. I see SQL Server has CHARINDEX() which is similar, however it does not provide...
4
by: Deborah V. Gardner | last post by:
I have a field with values like this CO 03-10 CO 03-4 VI 03-8 CO 03-533 I would like these to sort for a report by the first two letters and the digits after the hyphen (-) like this
5
by: Peter | last post by:
I put the result into an array getting from another db, the arrangement should not be changed, MemberList = "'007910', '006853', '007965'" SQL = "Select MemberID, name From Member" SQL = SQL...
4
by: fischerspooner | last post by:
Hi, I'm banging my head against the desk because I can't find a solution for the following simple problem. Case: There is a column in a table that has FamilyName and FirstName(s) in one field....
12
by: rodchar | last post by:
hey all, i'm getting a result that i don't understand i have a string "test1, test2" If InStr("test1") and InStr("test2") Then 'Inside EndIf The inside is not running for some reason. Any...
1
by: Denis | last post by:
Hi, I have a filed name called OwnerName where I typed in the persons first name then surname. I now have a need to display the surmane first then surname. Is there a way of reversing the...
3
by: lstrudeman | last post by:
Hello; A friend gave me this syntax and they are unavailable at the moment and I need this asap. I am trying to figure out how SQL figures this out. Below the syntax takes a field in a file and...
7
by: new to c | last post by:
Hi! I write the 2 codes int i; i = sizeof(long int); printf("%i", i); i = sizeof(int long); printf("%i", i);
3
by: Alex Pavluck | last post by:
I have a date stored like this '2004 - 2006' and I use this code to get startyear and stopyear StartYear: Trim(Left(,InStr(,"-")-1)) StopYear: Trim(Right(,InStr(,"-")-1)) Is there a way to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.