经典的asp使用SQL Server 2014将varchar转换为SQL查询中的int(Classic asp convert varchar to int in SQL query using SQL Server 2014)

我正在更新使用经典asp并使用SQL Server 2003的旧站点sortorder列存储为varchar 。

以下用于将varchar列转换为int ,然后可以在输出中对其进行排序(1-20数字)。 现在返回的记录从“1”变为“10”然后变为“11”等。它仍然将它们视为varchar 。

我是否需要将经典的asp文件转换为SQL Server 2014的新功能? 我试过演员,然后解析。

RQ="Select *, convert(int, sortorder) from table Where theid=1 order by sortorder" Set rs = Connect.Execute(Rq)

感谢您的任何帮助,您可以提供。 我已经在这里检查了答案,但是对于使用Classic ASP的较新的SQL Server数据库找不到任何东西。

I am updating a legacy site that uses classic asp and used to use SQL Server 2003. The sortorder column is stored as varchar.

The following used to convert the varchar column to an int that could then be sorted in in the output (1-20 numerically). Now the returned records go from "1" to "10" then "11" etc. It is still treating them as varchar.

Do I need to convert in the classic asp file to something new for SQL Server 2014? I have tried cast, and parse.

RQ="Select *, convert(int, sortorder) from table Where theid=1 order by sortorder" Set rs = Connect.Execute(Rq)

Thanks for any help you can provide. I have checked the answers here, but can't find anything for newer SQL Server database with Classic ASP.

最满意答案

您需要在ORDER BY子句中进行INT转换,以便正确排序:

RQ = "Select * from table Where theid=1 order by convert(int, sortorder)" Set rs = Connect.Execute(Rq)

只是在SELECT列的列表中转换没有帮助...

You need to be doing the conversion to INT in your ORDER BY clause so that it gets sorted properly:

RQ = "Select * from table Where theid=1 order by convert(int, sortorder)" Set rs = Connect.Execute(Rq)

Just converting in the list of columns of the SELECT doesn't help ...

更多推荐