How to store spaces in an attribute?

  • So a developer near me told me he hated NULLs because his reporting system could not handle them (thank you Sir Antony Richard Hoare for inventing the NULL..argh!). He said he replaced all the NULL's in the offending attribute with ' ' (note there is one space between those). I told him he need not bother with the space, just use '' (that's two distinct ' characters) otherwise he was just wasting space. Only it appears I was wrong. It led me to another question...So how to you store a string of spaces in an attribute?

    Here's my limited experiment

    -- build the table

    create table Little

    (spacer varchar(4) null)

    -- insert some rows with varying spaces

    insert into Little

    values ('')

    insert into Little

    values (' ')

    insert into Little

    values (' ')

    insert into Little

    values (' ')

    insert into Little

    values (' ')

    insert into Little

    values (space(4))

    insert into Little

    values (char(32)+char(32)+char(32)+char(32))

    -- Test the results

    select spacer,count(*) from Little

    group by spacer

    -- result is 7 identical rows

    select len(spacer),count(*) from Little

    group by len(spacer)

    -- same result

    do it right, or do it over and over, it's up to you

  • Take a look at "ANSI_PADDING" in Books Online.

    - 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

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

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