开发者

sql order by not working in classic asp loop

I have a sql query that orders the rows by开发者_StackOverflow中文版 an id, however it doesn't seem to output the data in order when in classic asp:

sSQL = "SELECT * FROM a ORDER BY ID DESC"
Set RS = ConnStr.Execute(sSQL)

<% DO WHILE NOT RS.EOF %> <td>
<br><p class='h1'>
<%=RS("ID")%>-
<%=RS("Title")%></p>
<% RS.MoveNext

Loop %> 

Database:

ID  Title
1    car
2    tree
3    dog

wrong asp output:

ID 
2
3
1


My fellow StackOverflowers, allow me to theorize on OPs context. It's a shot in the dark, with a little bit of experience in it. Consider this data structure:

declare  @mytable table (ID varchar(5))

insert into @mytable (ID) values
(' 1'), ('2'), (' 3')

select * from @mytable
order by ID desc

Notice the spaces before 1 and 3. Result:

ID
2
 3
 1

Since the browser will not visually render the empty spaces, OP might not be seeing them, but they might be there in the HTML.

That's the only way I can think of where ORDER BY <field> DESC would "apparently fail".


figured it out. But not sure why it works. I had an open

< td >

tag that I never closed in the loop. Why would this cause the order to be off?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜