TRIM is driving me nut

  • Actually it is working !

    You did not use a where clause, so all your rows should have the value "TechOwner_Department" for column Test !

    But all the records have been updated to the same value, and that's not what I want.

    If line1 is: 'aaaa ', it should be updated to 'aaaa'

    If line2 is: 'aaaaaa ', it should be updated to 'aaaaaa'

    If line3 is: 'aaaaaaaaa ', it should be updated to 'aaaaaaaaa'

    But all the 3 records have been updated to 'aaaa'

  • - it is a client setting. But that setting is used for any object at create time, so the object will use that setting.

    - Script the ddl for your tables (easiest with SSMS ) and you'll see which setting is in use.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution ๐Ÿ˜€

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • halifaxdal (10/17/2008)


    Actually it is working !

    You did not use a where clause, so all your rows should have the value "TechOwner_Department" for column Test !

    But all the records have been updated to the same value, and that's not what I want.

    If line1 is: 'aaaa ', it should be updated to 'aaaa'

    If line2 is: 'aaaaaa ', it should be updated to 'aaaaaa'

    If line3 is: 'aaaaaaaaa ', it should be updated to 'aaaaaaaaa'

    But all the 3 records have been updated to 'aaaa'

    Darn Access ๐Ÿ˜‰

    I thought it would use double quoted stuff for a string value ??

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution ๐Ÿ˜€

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • OK, here is the scripts: first one is not working, second one is working:

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[EPM](

    [ID] [int] NOT NULL,

    [AppID] [int] NULL,

    [AppCode] [varchar](5) NULL,

    [Description] [varchar](2000) NULL,

    [TechOwner_LastName] [varchar](40) NULL,

    [TechOwner_FirstName] [varchar](25) NULL,

    [TechOwner_Transit] [varchar](10) NULL,

    [TechOwner_Department] [varchar](50) NULL,

    [Tech_Vendor] [varchar](100) NULL,

    [ClientOwner_LastName] [varchar](40) NULL,

    [ClientOwner_FirstName] [varchar](25) NULL,

    [ClientOwner_Department] [varchar](60) NULL,

    [ClientSponsor] [varchar](50) NULL,

    [ClientCode] [char](2) NULL,

    [APM_UsageArea] [varchar](50) NULL,

    [BITA_GroupName] [varchar](255) NULL,

    [RelationshipManager] [nvarchar](255) NULL,

    [APM_ValueName] [nvarchar](255) NULL,

    [Overall_RiskRating] [nvarchar](255) NULL,

    [APM_DispositionName] [nvarchar](255) NULL,

    [DBR] [nvarchar](255) NULL,

    [RSK_FactorName] [nvarchar](255) NULL,

    [RSK_FactorRating] [nvarchar](255) NULL

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[SupportArea](

    [ID] [int] IDENTITY(1,1) NOT NULL,

    [OU1] [varchar](50) NULL,

    [OU2] [varchar](50) NULL,

    [OU3] [varchar](50) NULL,

    [OU4] [varchar](50) NULL,

    [OrgID] [int] NULL,

    [SupportArea] [varchar](50) NULL,

    [OrgUnit] [varchar](50) NULL,

    [Transit] [varchar](10) NULL,

    [Contact] [varchar](50) NULL,

    CONSTRAINT [PK_SupportAreaNew] PRIMARY KEY CLUSTERED

    (

    [ID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

  • AS far as ANSI_PADDING goes it isn't only the setting at table creation that matters it also matters what your setting is for

    insertion as well. BY default all the standard connection methods set it ON.

    Here is a way to find out if you have any odd characters in a string (uses a numbers/tally table[/url]):

    [font="Courier New"]DECLARE @test TABLE(id INT, string VARCHAR(10))

    -- if you already have a numbers/tally table you don't need this

    SELECT TOP 10 -- change this to the length of your column

       IDENTITY(INT, 1,1) AS N

    INTO

       #nums

    FROM

       sysobjects S1

    INSERT INTO @test

       SELECT

           1,

           'abc' --3 chars

       UNION ALL

       SELECT

           2,

           'abc ' -- 1 space 4 chars no trim 3 chars with trim

       UNION ALL

       SELECT

           3,

           'abc  ' -- 2 spaces 5 chars

       UNION ALL

       SELECT

           4,

           'abc' + CHAR(9) -- 1 tab 4 chars

       UNION ALL

       SELECT

           5,

           'abc' + CHAR(9)  + CHAR(9) -- 2 tabs 5 chars

    SELECT

       id,

       string,

       LEN(string) AS length,

       LEN(RTRIM(string)) AS trim_length,

       -- replace tabs with spaces

       LEN(RTRIM(REPLACE(string, CHAR(9), ' '))) AS no_tabs_trim_length,

       ASCII(SUBSTRING(string, N, 1)) AS ascii_val

    FROM

       @test JOIN

       #nums ON

           N <= DATALENGTH(string)

    WHERE

       -- eliminates spaces, numeric, and standard characters (A-Z, a-z)

       ASCII(SUBSTRING(string, N, 1)) NOT BETWEEN 20 AND 126

    DROP TABLE #nums

    [/font]

  • OK, using ASCII() I found for unknown reason char(160) was inserted as padding.

    I believe now I can clear out the table.

    But what the heck is char(160)?

  • Problem resolved.

    Thanks for all of you who pull me out of this muddy weird pond. But I still don't know why char(160) was padded.

  • According to http://ascii-table.com/ascii-extended-pc-list.php 160 is "รก - latin small letter a with acute"

  • Jack Corbett (10/17/2008)


    According to http://ascii-table.com/ascii-extended-pc-list.php 160 is "รก - latin small letter a with acute"

    I know it's รก, I just don't know why/how it is padded into my records, I don't want to see this kind of weird behavior happen again.

  • Now that the issue is resolved... Bitmaps?... Seriously? ๐Ÿ˜›

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. ๐Ÿ˜‰

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • Garadin (10/17/2008)


    Now that the issue is resolved... Bitmaps?... Seriously? ๐Ÿ˜›

    There you go.

  • halifaxdal (10/17/2008)


    Jack Corbett (10/17/2008)


    According to http://ascii-table.com/ascii-extended-pc-list.php 160 is "รก - latin small letter a with acute"

    I know it's รก, I just don't know why/how it is padded into my records, I don't want to see this kind of weird behavior happen again.

    It depends on the character set being used... in many character sets, CHAR(160) is a "hard-space" and it sometimes gets there from people using it to do left or right justification with a guarantee of no line break when it hits a word processor. It's not usually on purpose...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Oh... and the thing about the BITMAPs is that it's bloody well impossible to copy'n'paste code from them. And, it's actually more difficult for you to make the bit map than it is to copy and paste code. ๐Ÿ˜‰

    See the link in my signature for suggestions on how to post code and data on any forum. ๐Ÿ™‚

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • And the fact that bitmaps are HUGE. Not everyone that checks these forums has a high speed connection, and regardless, it just seems so... 20 years ago, to me =).

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. ๐Ÿ˜‰

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

Viewing 14 posts - 16 through 28 (of 28 total)

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