ASP, การแสดงฐานข้อมูล(MS Access)บนเวป ให้เรียงจากน้อยไปมาก แบบ A-Z แล้วค่อย ก-ฮ ได้ไหมครับ
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 253   7
URL.หัวข้อ / URL
ASP, การแสดงฐานข้อมูล(MS Access)บนเวป ให้เรียงจากน้อยไปมาก แบบ A-Z แล้วค่อย ก-ฮ ได้ไหมครับ

ASP, การแสดงฐานข้อมูล(MS Access)บนเวป ให้เรียงจากน้อยไปมาก แบบ A-Z แล้วค่อย ก-ฮ ได้ไหมครับ เพราะปัจจุบัน มันจะแสดง ก-ฮ แล้วค่อยแสดง A-Z ครับ(แบบนี้นายไม่ชอบครับ) ช่วยแนะนำวิธีแก้ปัญหานี้หน่อยนะครับ (ตัวอย่าง Source code ดังนี้ครับ)
-----------------
SQL="SELECT [Customer Point of Contact].*, [Customer].* FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] ORDER BY [first name] ASC;"
-----------------
ผลลัพธ์ คือ :
กนก
อนันต์
Anna
Samart
-----------------

Thanks in advance....



7 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R03850
ผมคิดว่าลอง Query ข้อมูลที่มีชื่อเป็นภาษาอังกฤษก่อน โดยใช้ Asc() ช่วย ซึ่งตัวสุดท้ายคือ z จะมีค่า = 122 แล้วค่อย Query ชื่อภาษาไทย แล้วลองใช้ Union เข้าช่วยดู เพื่อเชื่อม Query ทั้ง 2 เข้าด้วยกันอีกที่ ดังนี้

SQL="SELECT [Customer Point of Contact].*, [Customer].* FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] WHERE Asc(Left([first name],1))<=122 Union SELECT [Customer Point of Contact].*, [Customer].* FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] WHERE Asc(Left([first name],1))>122"

2 @R03853
ขอบคุณครับ แต่มันขึ้น Error ว่า

-------------------------------------------------------
Syntax error in expression
-------------------------------------------------------

ไม่ทราบว่าผมต้อง set อะไรเพิ่มเติมหรือเปล่าครับ
3 @R03856
ลองสร้าง Query นี้ใน Access ก่อน ว่า Syntax ถูกต้องหรือไม่

ถ้า Error ตั้งแต่อยู่ใน Access แล้ว

ลองเอา SQL มาดูใหม่อีกที่ครับ

ถ้าผ่าน ก็ให้ลองสร้างเป็น Query ใหม่ไปเลยก็ได้ แล้วค่อยเรียก Query นี้ใน ASP เลย จะทำงานไวกว่าแบบแรกมากครับ

จะได้

SQL = "Select * From ชื่อQueryใหม่"

4 @R03866
อาจารย์ สุภาพครับ ผมรันคิวรี่ใน Access แล้วขึ้น error ตามไฟล์ที่แนบมาครับ

ส่วน code sql ใน web file .asp เหมือนเดิมครับดังนี้ รบกวนเช็คอีกทีขอบคุณครับ
-----------------
SQL="SELECT [Customer Point of Contact].*, [Customer].* FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] ORDER BY [first name] ASC;"
-----------------
ผลลัพธ์ คือ :
กนก
อนันต์
Anna
Samart
-----------------



5 @R03867
ให้ลองเอาที่ละอันก่อนก่อน

อันแรก

SELECT [Customer Point of Contact].*, [Customer].* FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] WHERE Asc(Left([first name], 1))<=122

ดูว่าได้ผลมั๊ย

แล้วลองอันที่ 2

SELECT [Customer Point of Contact].*, [Customer].* FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] WHERE Asc(Left([first name], 1))>122

ได้ผลหรือไม่

แล้วค่อยนำทั้ง 2 มารวมกันด้วยคำว่า Union ครับ

SELECT [Customer Point of Contact].*, [Customer].* FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] WHERE Asc(Left([first name], 1))<=122
๊Union
SELECT [Customer Point of Contact].*, [Customer].* FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] WHERE Asc(Left([first name], 1))>122
6 @R03871
ขอบคุณครับ อาจารย์สุภาพ

ผมได้ทดลองทำตามดูแล้ว ถ้าเราทำทีละ query ก็จะได้ผลลัพธ์ถูกต้องครับคือ

อันที่ 1 จะได้
----------------------------
Anna
Samart
---------------------------


อันที่ 2 จะได้
---------------------------
กนก
อนันต์
---------------------------

หลังจากนั้นผมก็ทำการ Union มัน ปรากฎว่ามันโชว์ผิดดังนี้ครับ
SELECT [Customer Point of Contact].[customer id], [Customer Point of Contact].[first name], [Customer].[customer id] FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] and Asc(Left([first name], 1))<=122 UNION SELECT [Customer Point of Contact].[customer id], [Customer Point of Contact].[first name], [Customer].[customer id] FROM [Customer Point of Contact], [Customer] where [Customer Point of Contact].[Customer ID] = [Customer].[Customer ID] and Asc(Left([first name], 1))>122;


---------------------------
กนก
อนันต์
Anna
Samart

ซึ่งความต้องการของนายผม คือต้องการให้ Sort A-Z แล้วค่อย ก-ฮ นะครับ รบกวนอีกครั้งครับ

**** ข้อสังเกตุ : ผมไม่แน่ใจว่าเป็นปํญหามาจากตัว MS Access เองหรือเปล่า เพราะถ้าเราลองเปิด Table [Customer Point of Contact] ดูแล้วลอง sort ที่ field [First Name] จากน้อย ไป มาก หรือ จาก มาก ไป น้อย ก็จะได้ผลลัพธ์ ที่ผิดเหมือนข้างบนครับ ****
7 @R03874
ผมทำใน Access XP นะครับ

ผมลัพธ์ใน Access จะออกมาตามต้องการ

แต่พอมาลองกับ Access 97 ได้ผลลัพธ์ที่ผิดครับ

สงสัย Access 97 จะมีปัญหากับ Asc()
ซึ่งถ้าทำใน Debug window จะได้ผลลัพธ์ที่ OK

? Asc("ก")
161

แต่ถ้าทำใน Query จะได้ผลลัพธ์ที่ไม่ถูกต้องเลย????
จะได้ 63 ตลอด แม้ว่าจะขึ้นต้นด้วย ก หรือ อ ก็ตาม

MySort: Asc(Left("กนก",1))
63

MySort: Asc(Left("อนันต์",1))
63
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0727s