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.
| Author |
Topic |
|
pams_shadow
Starting Member
3 Posts |
Posted - 2004-02-24 : 10:03:29
|
| I'm using SQL Server Version 8.0. I'm attempting to find gaps in a varchar column. The column isn't sequential meaning the numbers go from 001000001111 to 001011101111 and I need to find any gaps with a number like 00100000%. I can find all of the gaps, but when I put the like statement in the where clause, I get "The conversion of the varchar value '003000000001' overflowed an int column. Maximum integer value exceeded." I know that this the min and max functions implicitly convert the varchar to an int. I've tried explicitly converting the varchar to bigint, but I get the exception, "Error converting datatype varchar to bigint." Any help would be appreciated. I can't change the column type to bigint, boss says it has to stay varchar. Boss doesn't like memory overhead, so using a temp table is out of the question too. Here is my sql statement that causes the int overflow exception.SELECT PartNumFROM PartMstr wWHERE (PartNum LIKE '00100000%') AND (PartNum IN (SELECT y.PartNum FROM PartMstr y INNER JOIN PartMstr x ON y.PartNum <> x.PartNum - 1 WHERE y.PartNum = (SELECT MAX(z.partnum) FROM partmstr z WHERE z.partnum < x.partnum)))Thanks in advance for any help! |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-02-24 : 11:25:07
|
| Can you post the table DDL? Including the PK and Indexes?AND Sample data like...INSERT INTO table(col list)SELECT data UNION ALLSELECT data UNION ALLSELECT data UNION ALLectSELECT dataBrett8-) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-02-24 : 11:31:40
|
..but you're problem is hereSELECT PartNum FROM PartMstr w WHERE PartNum LIKE '00100000%' AND PartNum IN ( SELECT y.PartNum FROM PartMstr y INNER JOIN PartMstr x ON y.PartNum <> x.PartNum - 1 WHERE y.PartNum = (SELECT MAX(z.partnum) FROM partmstr z WHERE z.partnum < x.partnum ) ) You have non numeric data in your varchar column, which is causing the error..What does the give you?SELECT COUNT(*) FROM PartMstr WHERE ISNUMERIC(partnum) = 0Brett8-) |
 |
|
|
pams_shadow
Starting Member
3 Posts |
Posted - 2004-02-24 : 11:44:28
|
| Brett,In answer to what does SELECT COUNT(*) FROM PartMstr WHERE ISNUMERIC(partnum) = 0return? The count returned is 1My table has the following columns and types, with the PK being PartNumPartNum char 12PartDesc varchar 30Brand varchar 12Status char 1QtyMin int 4QtyMax int 4Here's some sample dataPartNum | PartDesc | Brand | Status | QtyMin | QtyMax001000000101 | Fuse | LiteFuse | N | 10 | 25003011102589 | Bolt | Steele | N | 100 | 2500005001016658 | Belt | Amoco | D | 1 | 5 Hope this helps. |
 |
|
|
pams_shadow
Starting Member
3 Posts |
Posted - 2004-02-24 : 11:54:10
|
| Brett,I found the partnum that wasn't numeric and corrected it so that it is numeric, when I do the count now, it returns 0. However, I'm still getting the int column overflow exception.Thanks for helping me with this. :-)Pam |
 |
|
|
|
|
|
|
|