Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS SQL max id

Posted on 2006-07-18
6
Medium Priority
?
792 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:Mehram
6 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17129746
Hi campbel8,

change the datatype from int to long in the table
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17129747
the fields acc_id and paraccountid need to be of data type bigint, and not int
0
 
LVL 23

Expert Comment

by:apresto
ID: 17129751
sorry i meant:

Hi Mehram,

change the datatype from int to long in the table

:o)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Mehram
ID: 17129767
Sir the acc_id and paraccountid both are varchar (100)
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 17129802
>Sir the acc_id and paraccountid both are varchar (100)


select MAI=cast(max(cast(acc_id as bigint))+1 as varchar(100)), x.Paraccountid from
(select acc_id, paraccountid, title from AC_CHARTOFACC where paraccountid ='1002001001')x
group by x.paraccountid
0
 
LVL 7

Expert Comment

by:assyst
ID: 17129843
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
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What we learned in Webroot's webinar on multi-vector protection.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question