Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Arithmetic overflow error converting expression to

Author  Topic 

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2010-06-07 : 11:35:49
I found some code that tells me which columns changed during an update. But I'm getting the following error when I update a record in the table...

Arithmetic overflow error converting expression to data type bigint

Here is the relevant code (it fails on "SELECT @idTable = T.id...")...



DECLARE @idTable BIGINT

SELECT @idTable = T.id
FROM sysobjects P JOIN sysobjects T ON P.parent_obj = T.id
WHERE P.id = @@procid

-- Get COLUMNS_UPDATED if update
--
DECLARE @Columns_Updated VARCHAR(50)

SELECT @Columns_Updated = ISNULL(@Columns_Updated + ', ', '') + name
FROM syscolumns
WHERE id = @idTable
AND CONVERT(VARBINARY,REVERSE(COLUMNS_UPDATED())) & POWER(CONVERT(BIGINT, 2), colorder - 1) > 0

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-06-07 : 12:04:32
It's in your bitwise function. Your left side is varbinary, not int (or bigint)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2010-06-07 : 12:30:01
quote:
Originally posted by jimf

It's in your bitwise function. Your left side is varbinary, not int (or bigint)

Jim

Everyday I learn something that somebody else already knew



Awesome. Yeah - it was saying the problem was on line 27 which isn't near that stuff so that kind of threw me off.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-06-07 : 13:57:05
Was that really the issue? Was the value returned by COLUMNS_UPDATED() fucntion larger than a BIGINT?

You can perform bitwise operations on VARBINARY so it seems odd that'd be the actual issue.
Go to Top of Page
   

- Advertisement -