且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

sql server 2005中的Max()函数

更新时间:2023-02-07 09:58:59

首先,

如果activity_id包含从1到201的序列号,那为什么它是'nvarchar(6)'类型的列?糟糕的数据库设计!



你对查询结果的疑问必须是这样的:

activity_id comparsion的第一个字符后跟第二个,3 ...

因此,在99和201:

99-> 1st = 9

201-> 1st = 2



9> 2 =>因此,这导致99而不是201.



而不是在查询中强制转换,***将列类型更改为所需的值类型。
Firstly,
If "activity_id" contains serial nos from 1 to 201 then why is it a 'nvarchar(6)' type of column? Bad DB design!

Well the doubt you have regarding the query result must be something like:
first character of activity_id comparsion followed by 2nd, 3rd...
So, in 99 & 201:
99-> 1st = 9
201-> 1st = 2

9 > 2 => thus this results in 99 instead of 201.

Instead of casting in the query, best would be to change the column type to desired value types.