Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2011
    Posts
    47

    Unanswered: 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 ?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    use TRIM() function
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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 '))

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •