Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Replace NULL values in Query Analyzer output

Posted on 2006-05-31
5
Medium Priority
?
563 Views
Last Modified: 2008-01-09
I have a script that selects data that is exported to Excel.  Some of the fields have NULL values and I would like them to appear as blank in the Query Analyzer's output grid.  One field is a date and the other is an amount.  My script is enclosed.  I tried the ISNULL function with out success, it flipped the null dates to the year 1900.

Any thoughts or examples would be appreciated.  Thanks.


Exec sp_addlinkedserver
@server='ServerDocs',
@srvproduct='',
@provider='MSDASQL',
@provstr='DRIVER={SQL Server};SERVER=xx.x.xx.xx;UID=xxxxx;Initial Catalog=XXXXXXXXX'
GO

Exec sp_addlinkedsrvlogin
@rmtsrvname='ServerDocs',
@rmtuser='xxxxx',
@rmtpassword='xxxxxx'
GO

SELECT
Location,
PO_Num AS "P/O",
AgeGroup=
    Case
      when DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) >= 0
      and DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) <= 30
          then '0 - 30'
      when DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) >= 30
      and DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) <= 60
          then '30 - 60'
      when DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) >= 60
      and DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) <= 90
          then '60 - 90'
      when DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) >= 90
      and DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) <= 120
          then '90 - 120'
      when DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) >= 120
          then '120 + '
    end,
DATEDIFF(day, indexdb.dbo.FROM_UNIXTIME(F_CreateTime), getdate()) AS DaysOld,
Vendor_Name AS Vendor,
Invoice_Num AS Invoice,
E_INA55 AS "Inv. Date",                  <----
E_INA56 AS "Inv. Amount",              <----
E_NAME AS DocsNetID

FROM [indexdb].[f_sw].[VXQueue2_331]
LEFT OUTER JOIN [ServerDocs].[XSSICXS].[dbo].[ITEMS]
ON Invoice_Num = E_INA20 AND PO_Num = E_INA21
ORDER BY Location, PO_Num, DaysOld DESC
GO

Exec sp_droplinkedsrvlogin [ServerDocs], 'sa'
GO

Exec sp_dropserver [ServerDocs]
GO
0
Comment
Question by:dc900
5 Comments
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 16802144
ISNULL(E_INA55,'') AS "Inv. Date",                  <----
ISNULL(E_INA56,'') AS "Inv. Amount",              <----
0
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 16802149
I guess you already tried this... hmmm.
0
 
LVL 7

Accepted Solution

by:
LandyJ earned 600 total points
ID: 16802276
Try:
isNULL(cast(E_INA55 as varchar(50)), '')      
isNULL(cast(E_INA56 as varchar(50)), '')      

hth,
Landy
0
 
LVL 19

Assisted Solution

by:folderol
folderol earned 100 total points
ID: 16802748
From your question, I assume you are copy / pasting the result pane from Query Analyser into Excel.

This would be much easier if you were to use Data, Import External Data, New Database Query, from inside Excel and place your query there.  Nulls are automatically blanked by Excel when the returned set of data is written to the range of cells you specified in the external data wizard.

Otherwise, I think you can go with LandyJ posted code.

Tom
0
 

Author Comment

by:dc900
ID: 16807038
Thank you.  Your suggestion resolved my problem.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question