473,385 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

SYSTEM_USER automatic RTRIM of trailing spaces in 2000, but not 2005?

Hey all, I've noticed an obscure little quirk: it appears that if you
use a login with trailing spaces on the name, SYSTEM_USER
automatically trims those trailing spaces in SQL Server 2000, but not
SQL Server 2005.

Anybody know if this change in behavior is documented? If it is
intentional?

Is there a "quick fix" to revert to the old behavior (to automatically
RTRIM the results of SYSTEM_USER in 2005) until code can be changed?

Thanks in advance for any replies!
Aug 21 '08 #1
5 2931
(br************@gmail.com) writes:
Hey all, I've noticed an obscure little quirk: it appears that if you
use a login with trailing spaces on the name, SYSTEM_USER
automatically trims those trailing spaces in SQL Server 2000, but not
SQL Server 2005.

Anybody know if this change in behavior is documented? If it is
intentional?
It's surely intentional. The SQL 2000 behaviour strikes me as flat out
wrong. If the login "pelle " did something bad, he should be able to
put the blame on pelle without spaces.
Is there a "quick fix" to revert to the old behavior (to automatically
RTRIM the results of SYSTEM_USER in 2005) until code can be changed?
I would suggest that it would be incorrect to trim the result. I would
consider those spaces to be significant.


--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Aug 21 '08 #2
On Aug 21, 5:59*pm, Erland Sommarskog <esq...@sommarskog.sewrote:
*(brian.j.par...@gmail.com) writes:
Hey all, I've noticed an obscure little quirk: it appears that if you
use a login with trailing spaces on the name, SYSTEM_USER
automatically trims those trailing spaces in SQL Server 2000, but not
SQL Server 2005.

I would suggest that it would be incorrect to trim the result. I would
consider those spaces to be significant.
I agree, and I'm working out a long-term plan to consistently and
properly handle the logins. Unfortunately, we've got a ton of table
defaults and code built around this expectation. So until I can
actually do what's right, I was looking for a workaround that would
help clients who've moved to SQL Server 2005 avoid the quirky behavior
cropping up.

I don't think there is a workaround, but... I am surprised, because
even if the new behavior is correct (I agree it is) it is a breaking
change that doesn't seem to be documented anywhere.
Aug 25 '08 #3
(br************@gmail.com) writes:
I don't think there is a workaround, but... I am surprised, because
even if the new behavior is correct (I agree it is) it is a breaking
change that doesn't seem to be documented anywhere.
Hm, I'm not sure that I see any change. I rand this on SQL 2000 SP4:

sp_addlogin 'spacy ', nisse

Then I connected:

osql -P nisse -U "spacy "

And ran:

select '<' + SYSTEM_USER + '>'

The result:

<spacy >

So maybe there is some other difference here. Maybe you slept over
SP4, and migrated from SP3? Or maybe you rebuilt your tables from
scripts on SQL 2005, and had ANSI_PADDING ON, while you had it off
on SQL 2000?

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Aug 25 '08 #4
On Aug 25, 5:03*pm, Erland Sommarskog <esq...@sommarskog.sewrote:
Hm, I'm not sure that I see any change. I rand this on SQL 2000 SP4:

* *sp_addlogin 'spacy * ', nisse

Then I connected:

* *osql -P nisse -U "spacy * "

And ran:

* *select '<' + SYSTEM_USER + '>'

The result:

* *<spacy * >
That is very weird. I used Management Studio instead of osql, but I
just used your exact commands to create the 'spacy ' login on both
a 2005 and 2000 SQL Server here, and I do get different behavior; 2000
trims the trailing spaces.

I double checked @@version on the 2000 server and it gives me
8.00.2050, which is a post-SP4 hotfix. Since it's a direct create-
login-SYSTEM_USER check, it's not going into any tables I created
either...
Aug 28 '08 #5
(br************@gmail.com) writes:
That is very weird. I used Management Studio instead of osql, but I
just used your exact commands to create the 'spacy ' login on both
a 2005 and 2000 SQL Server here, and I do get different behavior; 2000
trims the trailing spaces.

I double checked @@version on the 2000 server and it gives me
8.00.2050, which is a post-SP4 hotfix. Since it's a direct create-
login-SYSTEM_USER check, it's not going into any tables I created
either...
I think I have it: on SQL 2000, SYSTEM_USER gives you string actually used
when you logged in. That is, the trailing spaces are included if you
provide them when you log in.

On SQL 2005, SYSTEM_USER gives the name as it stored in system tables, no
matter whether you provided trailing spaces or not when you logged in.

Note that this cuts both ways. You can provide trailing spaces when you
log in, even there are no trailing spaces in your login name, and
SQL Server will let you in. SYSTEM_USER will report those trailing spaces
on SQL 2000, but not on SQL 2005.

Apparently this changes is not documented, but there were a lot of
changes to system tables and security in SQL 2005, so it may not have
been intentional. MS may not have been aware of how it actually worked
in SQL 2000. After all, trailing spaces in login names does not appear
to be a very common thing...
To make this a little more confusing, SQL 2005 adds a new function,
original_login(). This function appears to always trim trailing spaces
(and never add any).

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Aug 28 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jay Chan | last post by:
I am trying to export data from a SQLServer database into a text file using a stored procedure. I want to be able to read it and debug it easily; therefore, I want all the columns to indent nicely....
3
by: Zlatko Matić | last post by:
Excuse me, what is the difference between user and system_user and which function should be used in audit trail table ? Thanks.
1
by: Lynn.Tilby | last post by:
In trying to trim some data while selecting and loading from 2 tables into 1 I get the following: SELECT TRIM(TRAILING ' ' FROM s.strk_sym_cmplt), TRIM(TRAILING ' ' FROM s.stk_sym), s.c_p,...
4
by: rajdb2 | last post by:
Hi, I am using the following sql statement SELECT rtrim(rtrim(coalesce(substr(char(v.creationdate),1,4) || '-' || substr(char(v.creationdate),6,2) || '-' || substr(char(v.creationdate),9,2) ||...
7
by: ITM | last post by:
Can anyone tell me how I can prevent Access adding trailing spaces when I insert a value into a Text column? For example, if I execute the following statement: UPDATE Log SET Log.Title =...
3
by: Andy B | last post by:
I've tried using Trim or RTrim to strip trailing space characters from my data. When I check on the transformed data space characters are still there. We have an address table containing two...
2
by: David Richards | last post by:
Hi, Hopefully someone can help me. I have setup a continuous form that displays customer names and addresses. I have then place a txt box on the form header. Using the onChange event I've setup...
2
by: David Teran | last post by:
Hi, i am using Postgres 7.4.2 with jdbc. Every time i try to select a varchar the SQL generated by the jdbc driver uses RTRIM(t0.columnname) which breaks an existing application. Is this normal,...
4
by: Mintyman | last post by:
Hi, I have erronous white space at the end of my 'description' field within my 'product' table. I tried using the RTRIM function but it won't let me because it is a TEXTBLOB (text) field. Can...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.