ahsan ashfaq

ahsan ashfaq

  • NA
  • 14
  • 0

Max() in sql server 2005

Jul 14 2010 1:31 AM
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)