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
 Transact-SQL (2000)
 CONVERT function - SQL Server 7 v SQL Server 2000

Author  Topic 

jones_d
Yak Posting Veteran

61 Posts

Posted - 2004-10-12 : 07:15:53
Hi,

I have a piece if code in a SQL Server 7 database using the CONVERT function:
SELECT CONVERT(varchar(6),[CONLEG]) + 'M' tran_id from sa_lbook

To focus on 1 record in sa_lbok for simplicity:
This returns "CASHM" when the code is executed. This is correct. "CASH" is the value in CONLEG in sa_lbook.

However, when I run the same code in SQL Server 2000 I get "CASH M" as the result.

In SQL Server 2000 because I am converting it to a varchar(6) and my value from sa_lbook is only 4 characters - It is appending 2 blank spaces to the end to makeup the six characters.

In SQL Server 2000 the compatibility level of the database is 70 - SQL Server 7 compatible.

My understanding of varchar is that it only uses \ pads the amount that the string requires - not like char which will reserve the size of the char datatype regardless of the size of the string stored in it.

The length of the value in the CONLEG field is 4. I used the LEN function to check that.

Does anyone know why this might be occurring? Is there a DB setting I can change?

Many Thanks for any ideas or suggestions you can provide.
   

- Advertisement -