Removing unwanted space in the result of SELECT query

  • Hi....

    In my table there is a row which contains data imported from a file. In tha table in a column after the name extra unwanted space also accidently included.

    The problem is while executing the query having WHERE condition i am not geting the result.

    For eg Select name from

    where name = 'name' since name has many spaces trailing it will not give the result . To get the result i have to insert correct extra spaces .

    In .NET on using Trim function in the executereader this is not working.

    Any good solution please reply as soon as possible.

    Thanks and Regards

    Sankar

  • Are you trying to do something like this:

    IF OBJECT_ID(N'tempdb..#T') IS NOT NULL

    DROP TABLE #T;

    CREATE TABLE #T (

    Col1 VARCHAR(100));

    INSERT INTO #T(Col1)

    VALUES ('A ');

    SELECT *

    FROM #T

    WHERE Col1 = 'A';

    That query works, so I'm not sure what you're running into. Can you provide a table and some data and a sample query, that does what you're running into? With that, we can probably help more.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Look up RTRIM() in Books Online.

    Check the datatype of the column 'name' - is it CHAR()? Sounds like it should be VARCHAR().

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply