Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

NULL value returning in output Expand / Collapse
Author
Message
Posted Monday, May 12, 2008 7:20 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, May 25, 2011 8:38 AM
Points: 2, Visits: 27
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



Post #498754
Posted Monday, May 12, 2008 11:16 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, November 21, 2013 2:59 PM
Points: 1,329, Visits: 807
What about the following:

SELECT CHAR(0) TEST1, CHAR(0) TEST2
Post #498980
Posted Tuesday, May 13, 2008 11:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, May 25, 2011 8:38 AM
Points: 2, Visits: 27
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...
Post #499862
Posted Tuesday, May 13, 2008 12:53 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 10:04 AM
Points: 15,442, Visits: 9,590
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
Post #499912
Posted Tuesday, August 31, 2010 7:25 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 31, 2010 8:05 AM
Points: 10, Visits: 25
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
Post #977958
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse