NULL value returning in output

  • I'm part of a group of business-side analysts that use SQL 2005 to provide data directly to users within our organization, often ad hoc directly from SQL Server Management Studio. One our senior SQL DBAs suggested I post this question here as this had him completely stumped.

    In SQL 2000 when the output is set to text tab delimited the query below will not actually return 'NULL' in the ouptut.

    SELECT NULL TEST1, NULL TEST2

    That is the desired result

    SQL 2005, however, with the same output settings (text tab delimited), returns 'NULL' in the output

    I can use the isnull or coalesce functions to code around this but it is a bit of pain. Has anyone ever found a fix or workaround (other than isnull and coalesce)?

    Don

  • What about the following:

    SELECT CHAR(0) TEST1, CHAR(0) TEST2

  • Thanks for the response. That seems to be the same thing as using isnull or coalesce functions, though? I'm looking more for a setting in SQL 2005 to make it so the 'NULL' value doesn't actually return in the output. Otherwise we have to add isnull or coalesce to every single column in the final query of a script. SQL 2000 was this way by default (if your default output is tab delimited text). Maybe a bug in 2000 or 2005?

    Sorry I should have made that more clear

    Just sort of a nuiscance. We do a ton of ad hoc reporting straight from our various data sources and some members of our reporting audience get confused by the NULL value so we have to either use isnull, coalesce, etc, or find / replace when data's exported to excell...

  • Per Books Online, the Null thing in result sets is intentional. Probably to make it easier to visually differentiate Null from a zero-length string.

    I think your best option is coalesce/isnull on the columns in the query.

    - 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

  • We have recently upgraded our SQL and are having the same issue, but I don't know how to change my statement to get blank results instead of "null" in my result set. Can you show me what to change?

    SELECT MPIN, ProvType, LastName, FirstName,

    Case

    When PrimSpec='040' then MI else null end as MID

    FROM dbo.PROVIDER

Viewing 5 posts - 1 through 4 (of 4 total)

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