Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

ms access - How to display a table order by code (like 01, 02… then null columns)?

How to display a table order by code (like 01, 02… then null columns)?

Using Access 2003 Database

Table

Name Title code Nationality code

Raja       05       03
Ramu       03      
Vijay      01       02
John       04       01
Roby       06  
Abilash    02       05

So on…,

I want to display a table order by title code, nationality code

In my “nationality code” field some of the columns are null, so I want to display a table order by title code, nationality code (like 01, 02… then null columns)

My query.

Select * from table order by nationality code, title code

Name      Title    Nationality
Ramu         03 
Roby         06 
John         04       01
Vijay       01       02
Raja         05       03
Abilash      02       05

But Null value is coming first in the nationality code, I want to display nationality code like 01, 02, 03, 05 then null values

Need Query Help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using the Nz function to provide a value for NULL columns, for example ORDER BY Nz(Nationality,9999999)

Note the NZ() will only work within the Access user interface. For a more neutral approach, you could try an expression in the ORDER BY clause e.g. something like

ORDER BY (LEN(nationality_code) > 0), nationality_code, title_code;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...