Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

How to get a row number which is failing during conversion Expand / Collapse
Author
Message
Posted Friday, January 23, 2009 9:23 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, March 16, 2012 3:51 PM
Points: 83, Visits: 300
I have about 20000 records in the SELECT clause and one of them is failing during conversion spitting out the following error message. "Arithmetic overflow error converting varchar to data type numeric.
" Is there a way to find out which row is failing?
Post #642566
Posted Friday, January 23, 2009 9:38 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, March 15, 2014 4:31 AM
Points: 2,808, Visits: 7,173
There will probably be a row that has a character that cannot be converted to integer.

try using this code to find the offending row(s)

SELECT * FROM YourTable
WHERE ISNUMERIC(YourColumn)=0

Post #642589
Posted Friday, January 23, 2009 9:41 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, March 16, 2012 3:51 PM
Points: 83, Visits: 300

Thanks for the reponse.

But that is not going to work because I am only selecting the records where ISNUMERIC(mycloumn) = 1.

Post #642592
Posted Friday, January 23, 2009 9:48 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, February 24, 2010 4:10 AM
Points: 1,553, Visits: 2,232
Steve, cause it's an overflow I recon it's not that there is char

Also be careful because
This will return a 1 for ISNUMERIC but it's not convertible: '10,0'.


What I normally do is run a top until I find a subset of data that contains my bad value and then I go from there.
What data type are you converting to?


----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley


Posting Best Practices
Numbers / Tally Tables

SQL-4-Life
Post #642600
Posted Friday, January 23, 2009 9:48 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 12:06 PM
Points: 10,910, Visits: 12,546
Check out the BOL entry for IsNumeric. "+", "-", ".", and currency symbols are all considered Numeric. Change your where clause to:

Where
Column NOT LIKE '%[^0-9]%'

This says only allow numbers ignoring all other characters. If you want to allow decimals and negatives you can add the necessary characters to the mask.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #642601
Posted Friday, January 23, 2009 9:50 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, March 16, 2012 3:51 PM
Points: 83, Visits: 300
Converting to deciman(12,7)
Post #642603
Posted Friday, January 23, 2009 9:51 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, March 15, 2014 4:31 AM
Points: 2,808, Visits: 7,173
Okay sorry i mis-read the question..

It seems like the value is too big to fit into a numeric column
Post #642605
Posted Friday, January 23, 2009 9:53 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, February 24, 2010 4:10 AM
Points: 1,553, Visits: 2,232
Also your select statement will normally return a number of rows before it actually falls over so you could use that as a point in the DB to start looking for bad data

e.g

DECLARE  @TMP TABLE 
(COl1 VARCHAR(100))
INSERT INTO @tmp
SELECT '1' UNION ALL
SELECT '1111111111111111111111'

SELECT CAST(col1 as decimal(12,7))
FROM @tmp

This fails but it also return one row, so I know that it's after the first row etc...


----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley


Posting Best Practices
Numbers / Tally Tables

SQL-4-Life
Post #642611
Posted Friday, January 23, 2009 9:57 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, February 24, 2010 4:10 AM
Points: 1,553, Visits: 2,232
The only other thing I can think of it to return all rows that have a Len(Col) greater than what your decimal can hold and look at those

----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley


Posting Best Practices
Numbers / Tally Tables

SQL-4-Life
Post #642617
Posted Friday, January 23, 2009 10:05 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, February 24, 2010 4:10 AM
Points: 1,553, Visits: 2,232
Ok assuming all your values are numeric then try this:
in the where clause
	CHARINDEX('.',col1) > 6
OR
(CHARINDEX('.',col1) = 0 AND LEN(col1) > 5)

Here is my example for returning values that would overflow.

DECLARE  @TMP TABLE 
(COl1 VARCHAR(100))
INSERT INTO @tmp
SELECT '1' UNION ALL
SELECT '1' UNION ALL
SELECT '1' UNION ALL
SELECT '1' UNION ALL
SELECT '1' UNION ALL
SELECT '1' UNION ALL
SELECT '1' UNION ALL
SELECT '1' UNION ALL
SELECT '1' UNION ALL
SELECT '92345.1234567' UNION ALL
SELECT '12345.12345671' UNION ALL
SELECT '123456.1234567' UNION ALL
SELECT '111111111111111111111111111111' UNION ALL
SELECT '1234567890'

SELECT
--CAST(col1 as decimal(12,7))
col1
FROM @tmp
WHERE
CHARINDEX('.',col1) > 6
OR
(CHARINDEX('.',col1) = 0 AND LEN(col1) > 5)



----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley


Posting Best Practices
Numbers / Tally Tables

SQL-4-Life
Post #642625
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse