Solved

MS SQL max id

Posted on 2006-07-18
6
789 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

734 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