Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


NULL value returning in output


NULL value returning in output

Author
Message
dschenckl
dschenckl
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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
jim.powers
jim.powers
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1343 Visits: 839
What about the following:

SELECT CHAR(0) TEST1, CHAR(0) TEST2
dschenckl
dschenckl
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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...
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14375 Visits: 9729
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
jennifer_l_hogan
jennifer_l_hogan
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search