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 2000 Forums
 SQL Server Administration (2000)
 Same Code works different on two databases

Author  Topic 

nizmaylo
Constraint Violating Yak Guru

258 Posts

Posted - 2001-08-30 : 12:06:53
I have being experiencing an unusual problem.
The code is very simple.
DECLARE @customerName nvarchar(500)
SELECT TOP 10 @customerName=COALESCE(@customerName,'|','') + customerName
FROM customers

The names are usually 20-25 characters long at the most, so we would expect them to fit the 500 variable.

Which it does on the development database.

When it queries the same 10 records on production database, it only gets the last customer or the first one (depending on sort order). It doesn't act the typical way, just simply truncating characters, which don't fit.

However, if I change the length of varchar to 1000 - it works.

From the first glance there is no difference between the production and development databases - they are only 2 months apart and the top 10 records in customer table are definitely the same.

I tried using RTRIM but it didn't work since there is nothing to trim there.

I checked DATALENGHT for @customerName and it's only 158 on both databases.

I don't seem to be able to detect the difference, but there must be some which makes a 158 string not to fit a 500 variable.

PS - customers table is populated using MS Access 2000 Project as Front End.


helena
   

- Advertisement -