按 asc Sql 查询排序
Order by asc Sql query
我有 sql 按 asc 查询订购,我必须订购包含整数值的 varchar 字段(我无法将数据类型更改为 int,因为其中已经有很多数据 table 更改可能会丢失数据)。排序结果如下
1
2
3
.
.
8
9
10
101
102
103
.
.
109
11
110
111
.
.
119
12
结果应该是
1
2
3
.
.
8
9
10
11
12
查询是
dbAccess.execute("SELECT [id],[SNo],LetterSNO,[SubjectOfLetter],[FrmWhere],[WhomTosend],
(Cast(Day(DateOfRecieve) as Varchar(3))+'/'+Cast(Month(DateOfRecieve) as Varchar(2))+'/'+Cast(Year(DateOfRecieve) as Varchar(4))) as DateOfRecieve ,[Remarks] ,[User_IPAddress],
(Cast(Day(DateOfSending) as Varchar(3))+'/'+Cast(Month(DateOfSending) as Varchar(2))+'/'+Cast(Year(DateOfSending) as Varchar(4))) as DateOfSending
FROM [MpscdrcTESTING].[dbo].[tbl_PostalEntry]
where DateOfRecieve between '" + TextBox1.Text.Trim() + "' and '" + TextBox2.Text.Trim() + "' order by SNo asc";
请帮忙
试试这个
ORDER BY CAST(sNO as INT)
我有 sql 按 asc 查询订购,我必须订购包含整数值的 varchar 字段(我无法将数据类型更改为 int,因为其中已经有很多数据 table 更改可能会丢失数据)。排序结果如下
1
2
3
.
.
8
9
10
101
102
103
.
.
109
11
110
111
.
.
119
12
结果应该是
1
2
3
.
.
8
9
10
11
12
查询是
dbAccess.execute("SELECT [id],[SNo],LetterSNO,[SubjectOfLetter],[FrmWhere],[WhomTosend],
(Cast(Day(DateOfRecieve) as Varchar(3))+'/'+Cast(Month(DateOfRecieve) as Varchar(2))+'/'+Cast(Year(DateOfRecieve) as Varchar(4))) as DateOfRecieve ,[Remarks] ,[User_IPAddress],
(Cast(Day(DateOfSending) as Varchar(3))+'/'+Cast(Month(DateOfSending) as Varchar(2))+'/'+Cast(Year(DateOfSending) as Varchar(4))) as DateOfSending
FROM [MpscdrcTESTING].[dbo].[tbl_PostalEntry]
where DateOfRecieve between '" + TextBox1.Text.Trim() + "' and '" + TextBox2.Text.Trim() + "' order by SNo asc";
请帮忙
试试这个
ORDER BY CAST(sNO as INT)