Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: ASP and SQL Server: Problems with unwanted spaces after data


Message #1 by "Dean" <spinout@i...> on Wed, 16 Jan 2002 15:36:32
Hi There,

Can anyone help me with this problem I'm having.



I have an SQL server database. I have a table set up with a column that 

allows up to 20 characters.

When I enter data that say it's 10 characters long it fills the 10 

remaining characters with blank spaces.



When I then extract this data from the database through ASP my If 

statement fails because of the spaces.



For example



If RsUserName = "JohnDoe" then

  Some condition

Else

  Some condition

End If



this would fail when I want it to be true because RsUserName wouldn't 

equal 'JohnDoe' it would actually equal 'JohnDoe           ' with a heap 

of unwanted spaces at the end put there by the SQL server because the data 

isn't as long as the allowable number of characters.



Is there a way I can solve this problem? Either stop SQL server from 

entering all those unwanted spaces? or at the very least to strip them out 

when I'm trying to use the data in an if/then/else statement??



Thanks.

Message #2 by =?iso-8859-1?Q?=22Buonocore=2C_Dani=EBl=22?=--- <DBuonoco@T...> on Wed, 16 Jan 2002 15:33:22 -0000
Hi,



Use trim to delete the spaces



If Trim(RsUserName) = "JohnDoe" then

   Some condition

Else

   Some condition

End If



Daniel.



> -----Original Message-----

> From: Dean [mailto:spinout@i...] 

> Sent: woensdag 16 januari 2002 16:37

> To: ASP Databases

> Subject: [asp_databases] ASP and SQL Server: Problems with 

> unwanted spaces after data

> 

> 

> Hi There,

> Can anyone help me with this problem I'm having.

> 

> I have an SQL server database. I have a table set up with a 

> column that 

> allows up to 20 characters.

> When I enter data that say it's 10 characters long it fills the 10 

> remaining characters with blank spaces.

> 

> When I then extract this data from the database through ASP my If 

> statement fails because of the spaces.

> 

> For example

> 

> If RsUserName = "JohnDoe" then

>   Some condition

> Else

>   Some condition

> End If

> 

> this would fail when I want it to be true because RsUserName wouldn't 

> equal 'JohnDoe' it would actually equal 'JohnDoe           ' 

> with a heap 

> of unwanted spaces at the end put there by the SQL server 

> because the data 

> isn't as long as the allowable number of characters.

> 

> Is there a way I can solve this problem? Either stop SQL server from 

> entering all those unwanted spaces? or at the very least to 

> strip them out 

> when I'm trying to use the data in an if/then/else statement??

> 

> Thanks.

> 




> $subst('Email.Unsub').

> 

Message #3 by ReddySri@c... on Wed, 16 Jan 2002 09:24:04 -0600
Use TRIM to truncate the spaces in ASP.



Example :

If Trim(RsUserName) = "JohnDoe" Then

	SomeCondition

Else

	SomeOtherCondition

End If





Srini Reddy







-----Original Message-----

From: Dean [mailto:spinout@i...]

Sent: Wednesday, January 16, 2002 10:37 AM

To: ASP Databases

Subject: [asp_databases] ASP and SQL Server: Problems with unwanted

spaces after data





Hi There,

Can anyone help me with this problem I'm having.



I have an SQL server database. I have a table set up with a column that 

allows up to 20 characters.

When I enter data that say it's 10 characters long it fills the 10 

remaining characters with blank spaces.



When I then extract this data from the database through ASP my If 

statement fails because of the spaces.



For example



If RsUserName = "JohnDoe" then

  Some condition

Else

  Some condition

End If



this would fail when I want it to be true because RsUserName wouldn't 

equal 'JohnDoe' it would actually equal 'JohnDoe           ' with a heap 

of unwanted spaces at the end put there by the SQL server because the data 

isn't as long as the allowable number of characters.



Is there a way I can solve this problem? Either stop SQL server from 

entering all those unwanted spaces? or at the very least to strip them out 

when I'm trying to use the data in an if/then/else statement??



Thanks.






$subst('Email.Unsub').

Message #4 by "Kim Iwan Hansen" <kimiwan@k...> on Wed, 16 Jan 2002 16:52:41 +0100
My experience with sql server is limited, but isn't this just a matter of

making it a varchar instead of a char??



A varchar would adjust the length to the size of the word (up to the max

size of the field) where a char field will always be stored as the max

length (with blank spaces on the end of the word).



-Kim







> -----Original Message-----

> From: Dean [mailto:spinout@i...]

> Sent: 16. januar 2002 15:37

> To: ASP Databases

> Subject: [asp_databases] ASP and SQL Server: Problems with unwanted

> spaces after data

>

>

> Hi There,

> Can anyone help me with this problem I'm having.

>

> I have an SQL server database. I have a table set up with a column that

> allows up to 20 characters.

> When I enter data that say it's 10 characters long it fills the 10

> remaining characters with blank spaces.

>

> When I then extract this data from the database through ASP my If

> statement fails because of the spaces.

>

> For example

>

> If RsUserName = "JohnDoe" then

>   Some condition

> Else

>   Some condition

> End If

>

> this would fail when I want it to be true because RsUserName wouldn't

> equal 'JohnDoe' it would actually equal 'JohnDoe           ' with a heap

> of unwanted spaces at the end put there by the SQL server because

> the data

> isn't as long as the allowable number of characters.

>

> Is there a way I can solve this problem? Either stop SQL server from

> entering all those unwanted spaces? or at the very least to strip

> them out

> when I'm trying to use the data in an if/then/else statement??

>

> Thanks.

>




> $subst('Email.Unsub').

>



Message #5 by "Dean" <spinout@i...> on Wed, 16 Jan 2002 16:00:44
Thank you so much for your help!

Do any of you know if there is a way to stop SQL server inserting all 

those blank spaces after the data in the first place? This would save a 

lot of time and effort since I'm developing a rather large web application 

and would save a lot of adding the Trim function all over the place.
Message #6 by "Dean" <spinout@i...> on Wed, 16 Jan 2002 16:09:35
> My experience with sql server is limited, but isn't this just a matter of

> making it a varchar instead of a char??

> 

> A varchar would adjust the length to the size of the word (up to the max

> size of the field) where a char field will always be stored as the max

> length (with blank spaces on the end of the word).

> 

> -Kim

> 





You know what Kim, you really could have a point there! My experience with 

sql server is limited too. It's something I've really only started to 

'play' with over the past 6 or so months. Thank you so much for that tip. 

Something I'm bound not to forget given the amount of problems char has 

given me with blank spaces :)
Message #7 by "Tomm Matthis" <matthis@b...> on Wed, 16 Jan 2002 12:15:52 -0500
Make the field varchar instead of char.



-- Tomm



> -----Original Message-----

> From: Dean [mailto:spinout@i...]

> Sent: Wednesday, January 16, 2002 3:37 PM

> To: ASP Databases

> Subject: [asp_databases] ASP and SQL Server: Problems with unwanted

> spaces after data

> 

> 

> Hi There,

> Can anyone help me with this problem I'm having.

> 

> I have an SQL server database. I have a table set up with a column that 

> allows up to 20 characters.

> When I enter data that say it's 10 characters long it fills the 10 

> remaining characters with blank spaces.

> 

> When I then extract this data from the database through ASP my If 

> statement fails because of the spaces.

> 

> For example

> 

> If RsUserName = "JohnDoe" then

>   Some condition

> Else

>   Some condition

> End If

> 

> this would fail when I want it to be true because RsUserName wouldn't 

> equal 'JohnDoe' it would actually equal 'JohnDoe           ' with a heap 

> of unwanted spaces at the end put there by the SQL server because the data 

> isn't as long as the allowable number of characters.

> 

> Is there a way I can solve this problem? Either stop SQL server from 

> entering all those unwanted spaces? or at the very least to strip them out 

> when I'm trying to use the data in an if/then/else statement??

> 

> Thanks.

> 




> $subst('Email.Unsub').

Message #8 by "Drew, Ron" <RDrew@B...> on Wed, 16 Jan 2002 12:40:09 -0500
If Trim(RsUserName) =3D "JohnDoe" then

  Some condition

Else

  Some condition

End If



-----Original Message-----

From: Dean [mailto:spinout@i...]

Sent: Wednesday, January 16, 2002 10:37 AM

To: ASP Databases

Subject: [asp_databases] ASP and SQL Server: Problems with unwanted

spaces after data





Hi There,

Can anyone help me with this problem I'm having.



I have an SQL server database. I have a table set up with a column that

allows up to 20 characters.

When I enter data that say it's 10 characters long it fills the 10

remaining characters with blank spaces.



When I then extract this data from the database through ASP my If

statement fails because of the spaces.



For example



If RsUserName =3D "JohnDoe" then

  Some condition

Else

  Some condition

End If



this would fail when I want it to be true because RsUserName wouldn't

equal 'JohnDoe' it would actually equal 'JohnDoe           ' with a heap



of unwanted spaces at the end put there by the SQL server because the

data

isn't as long as the allowable number of characters.



Is there a way I can solve this problem? Either stop SQL server from

entering all those unwanted spaces? or at the very least to strip them

out

when I'm trying to use the data in an if/then/else statement??



Thanks.






$subst('Email.Unsub').

Message #9 by "Drew, Ron" <RDrew@B...> on Wed, 16 Jan 2002 12:42:45 -0500
This is very true  varchar versus char



-----Original Message-----

From: Kim Iwan Hansen [mailto:kimiwan@k...]

Sent: Wednesday, January 16, 2002 10:53 AM

To: ASP Databases

Subject: [asp_databases] RE: ASP and SQL Server: Problems with unwanted

spaces after data





My experience with sql server is limited, but isn't this just a matter

of making it a varchar instead of a char??



A varchar would adjust the length to the size of the word (up to the max

size of the field) where a char field will always be stored as the max

length (with blank spaces on the end of the word).



-Kim







> -----Original Message-----

> From: Dean [mailto:spinout@i...]

> Sent: 16. januar 2002 15:37

> To: ASP Databases

> Subject: [asp_databases] ASP and SQL Server: Problems with unwanted

> spaces after data

>

>

> Hi There,

> Can anyone help me with this problem I'm having.

>

> I have an SQL server database. I have a table set up with a column

> that allows up to 20 characters. When I enter data that say it's 10

> characters long it fills the 10 remaining characters with blank

> spaces.

>

> When I then extract this data from the database through ASP my If

> statement fails because of the spaces.

>

> For example

>

> If RsUserName =3D "JohnDoe" then

>   Some condition

> Else

>   Some condition

> End If

>

> this would fail when I want it to be true because RsUserName wouldn't

> equal 'JohnDoe' it would actually equal 'JohnDoe           ' with a

heap

> of unwanted spaces at the end put there by the SQL server because the

> data isn't as long as the allowable number of characters.

>

> Is there a way I can solve this problem? Either stop SQL server from

> entering all those unwanted spaces? or at the very least to strip them



> out when I'm trying to use the data in an if/then/else statement??

>

> Thanks.

>

> ---

> Change your mail options at http://p2p.wrox.com/manager.asp or to

> unsubscribe send a blank email to

> $subst('Email.Unsub').

>








$subst('Email.Unsub').


  Return to Index