0

Getting an error on line 1 of this code...

Select COUNT(MEM_REL) As MemberSub, CLM_CC2 As GroupNum
From Impact.dbo.tbl_mem, Impact.dbo.tbl_clm 
Where MEM_REL = '01'
Group by CLM_CC2

The error is:

MSg 8815, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int
9
  • becuase you are passing MEM_REL = '01' you have to pass MEM_REL = 1 Commented Aug 20, 2015 at 16:06
  • You are missing a JOIN in your FROM clause. Commented Aug 20, 2015 at 16:06
  • Where am I putting the join @GordonLinoff? Commented Aug 20, 2015 at 16:08
  • @tinka that has nothing to do with it. Commented Aug 20, 2015 at 16:08
  • 2
    You really should not use a comma separated list of tables. It works but it it a very old join style. You should be explicit and state that you want a CROSS JOIN. sqlblog.org/2009/10/08/bad-habits-to-kick-using-old-style-joins Commented Aug 20, 2015 at 16:12

1 Answer 1

2

Try introducing a proper relation to the query, right now you are getting a Cartesian product of the two tables. For example instead of the comma , use the key word JOIN to join two tables and then define the relation on what column you want to join these tables.

Once you have done the above the number of rows returned will dramatically decrease and the following query may work, if you have more than 2.2 billion rows in the following query then you may need to use COUNT_BIG() function instead of just COUNT()

Select COUNT(MEM_REL) As MemberSub
     , CLM_CC2 As GroupNum
From Impact.dbo.tbl_mem
INNER JOIN Impact.dbo.tbl_clm 
ON dbo.tbl_mem.[ReferencingColumn] = dbo.tbl_clm.[ReferencingColumn]
Where MEM_REL = '01'
Group by CLM_CC2

Query with COUNT_BIG()

Select COUNT_BIG(MEM_REL) As MemberSub
     , CLM_CC2 As GroupNum
From Impact.dbo.tbl_mem
INNER JOIN Impact.dbo.tbl_clm 
ON dbo.tbl_mem.[ReferencingColumn] = dbo.tbl_clm.[ReferencingColumn]
Where MEM_REL = '01'
Group by CLM_CC2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.