If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > problem while retrieving data from the db

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-11, 06:19
navedjobs navedjobs is offline
Registered User
 
Join Date: Sep 2011
Posts: 35
problem while retrieving data from the db

i m giving 50 varchar(50) space to my user to write there name in my app
but more often the name just occupy only 12 to 15 chars of space and left the other empty
so mine problem is when i try to fetch that name from he db then the name apears on the field along with all the empty space also appears
so suppose user entered name of length 10 we should get a string of length 10 while retrieving from the db but i m getting string of length 50 in which
data is just till 10 chars and rest is empty spaces
how to solve this problem ?
Reply With Quote
  #2 (permalink)  
Old 12-09-11, 06:37
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
use TRIM() function
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-09-11, 12:12
randirsa randirsa is offline
Registered User
 
Join Date: Nov 2011
Posts: 21
Sql Server doesn't have Trim() function. But SQL does have LTRIM() and RTRIM() which can trim leading and trailing spaces.

SELECT RTRIM(LTRIM(' data '))
Reply With Quote
  #4 (permalink)  
Old 12-09-11, 12:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by randirsa View Post
Sql Server doesn't have Trim() function. But SQL does have LTRIM() and RTRIM() which can trim leading and trailing spaces.
you copied that right off this page, and repeated the same logical confusion

SQL Server, the database product, doesn't have TRIM, so you have to use RTRIM and LTRIM

SQL, the standard language, does (and doesn't have RTRIM or LTRIM)

please make sure that you always say the full name "SQL Server" when you refer to microsoft's product, especially when you use both terms at the same time, like you did

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On