Link to home
Start Free TrialLog in
Avatar of Mehram
MehramFlag for Pakistan

asked on

MS SQL max id

Sir, I am using below statement and it is showing error following:

select MAI=max(acc_id)+1, x.Paraccountid from
(select acc_id, paraccountid, title from AC_CHARTOFACC where paraccountid ='1002001001')x
group by x.paraccountid


Error:
Server: Msg 248, Level 16, State 1, Line 1
The conversion of the varchar value '1002001001001' overflowed an int column. Maximum integer value exceeded.

Please help how to resolve this problem.

Rgds.
Mehram
Avatar of apresto
apresto
Flag of Italy image

Hi campbel8,

change the datatype from int to long in the table
Avatar of Guy Hengel [angelIII / a3]
the fields acc_id and paraccountid need to be of data type bigint, and not int
sorry i meant:

Hi Mehram,

change the datatype from int to long in the table

:o)
Avatar of Mehram

ASKER

Sir the acc_id and paraccountid both are varchar (100)
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of assyst
assyst

Try this query....

If its a varchar field, you have to convert it to a numeric field

We can make use of CONVERT funtion or CAST function for this purpose...

Convert(data type,field name)
Cast (field name as data type)

select MAI=max(convert(numeric,acc_id))+1, x.Paraccountid from
(select acc_id, paraccountid, title from AC_CHARTOFACC where paraccountid ='1002001001') x
group by x.paraccountid