1
Answer

Max() in sql server 2005

Ask a question
ahsan ashfaq

ahsan ashfaq

14y
1.6k
1
Hello all,
Thanks for reading my thread,

let me brief you first. I have a table "Activity_id"
and in the table i have a column name "activity_id" nvarchar(6)
it just contains Serial No.s from 1 to 201.

Now the issue.
select max(activity_id) from activity_id
                 This query returns value "99" which is incorrect.
select max(cast(activity_id as int)) from activity_id
                 This query returns the value "201". which is correct.

I can reckon that its because of nvarchar and casting to int. but will u plz elaborate how nvarchar values are compared so that 99 is greater than 201.


Thanks,
Ahsan Ashfaq

Answers (1)