Isnull question

  • I have to display string "not assigined" when a datefield is null in a table.

    I am using like ISNULL(datefiled, "not assigned"), but I am getting following error

    Syntax error converting character string to smalldatetime data type.

    Is there any way, I can acheive desired result.

    Please help

     

  • There's a little catch with the isnull function. It returns the same datatype and same lenght as the input value. This also means that each paramater must be of same type/length (unless you want to have unexpected truncatations).

    Maybe this could work but I can't test it :

    case when DateField is null then 'not assigned' else DateField end.

    Please notice that the case expression will always return a string (in this case ). So you'll have to keep this in mind when you code the application.

  • I tried your suggestion too, but same problem persists

    Please help

  • Alpoor...

    Try this: SELECT ISNULL(CAST(datefiled AS varchar(15)), 'Not Assigned')







    **ASCII stupid question, get a stupid ANSI !!!**

  • Yup, looks like you're stuck with the cast anyways :

    Declare @X as datetime

    set @X = GetDate()

    Select case when @X is null then 'some text' else @X end

    --2005-06-08 08:11:26.967

    set @X = null

    Select case when @X is null then 'some text' else CAST(@X AS Varchar(20)) end

    --some text, fails without the cast

  • Thanks Susheela

    It worked like champ. thanks again

  • hmm I think it's "sushila"

    .

  • "Call a rose by any other name...." <;-)







    **ASCII stupid question, get a stupid ANSI !!!**

  • Maybe... but it's still your correct nickname. .

  • Think anyone will take up the challenge??

    Maybe we should submit it as a question of the day .

  • Know what Remi - I think you should - maybe that's the only way you'll get people to respond!

    ps: Maybe Frank will respond by morning...or Chris...or anyone else in European time!!!

    pps: Sushila isn't my nickname...it's the real one...the nickname is "Rose"..haha!!<;-)







    **ASCII stupid question, get a stupid ANSI !!!**

  • Hehe.. first time I hear a name like that!! What's the language of origin?

  • C'est le pays le plus peuplé au monde après la Chine - dead giveaway huh!!!

    BTW - if you think of it as "sue" + "sheila" (some concatenation here...) it's easier!







    **ASCII stupid question, get a stupid ANSI !!!**

  • I'll avoid to show my total ignorance in that subject and won't put any guess out there . But since you talk about Suchie (how the h3II do you write that??), I'll go with Japan (Just remembered I can edit those things ).

  • In my opinion, If you are returning the data to an application that you have control of the source code, the front end UI should be doing a check for null values and handle how to display the information. It's better seperation of the layers. The data layer handles data, the presentation layer handles display.

Viewing 15 posts - 1 through 15 (of 16 total)

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