October 24, 2008 at 7:28 am
Hi all,
i have a problem with my application. It's designed to synchronize MySQL database with MSSQL database. However every now and then table CUSTOMERS is not updated as it should be. As i've seen from log file, fetched values of ID column (primary key) in MSSQL are not correct. For example, instead of values '00000', '000001', '00014', etc... the select statement returns values '0', '1', '14',... Basically all the zeros are wiped out. Data type of the column is nvarchar(10). The customer uses SQL Server 2000 Enterprise. However i didn't encounter this problem on my SQL Server 2005 with same (cloned) database.
This is the sql:
SELECT TOP 1000 ID FROM CUSTOMERS WHERE ID NOT IN (SELECT TOP 0 ID FROM CUSTOMERS ORDER BY ID ) ORDER BY ID
Thanks for any help,
U.
October 24, 2008 at 7:55 am
Mathematically, it is correct to show 1 instead of 00001 for the INTEGER data type
Maybe you can explicitly select it as NVARCHAR
if not, use REPLICATE to fill in the 0's
SELECT TOP 1000 ID = CAST(ID AS NVARCHAR(10))
FROM CUSTOMERS
WHERE ID NOT IN (SELECT TOP 0 ID FROM CUSTOMERS ORDER BY ID ) ORDER BY ID
October 24, 2008 at 12:24 pm
Hi Jerry, thank you for the quick answer.
I'll try your suggestion and report back.
U.
November 6, 2008 at 3:25 pm
Huh, i guess that solved the problem. The error doesn't show up anymore. Thank you again.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply