SQL Output file contains nulls but I'm using isnull in my select statement

94 Views Asked by At

SQL Output file contains nulls but I'm using isnull in my select statement Here is my code. I am still getting NULLs in my output file for columns Modifer1 and Modifier2.

Select 
    A.SvcProvSvcId as 'CDMCode',
    A.BillName,
    A.[CPT/HCPCSCdVal],
    isnull(A.[Modifier 1],'') as Modifier1,
    isnull(A.[Modifer 2],'') as Modifier2,
    A.RevCdVal,
    A.Price

into ##temp_CDM
    
From ##temp_CDMAllPrices A

inner join 
    (select max(isnull(LastRateChange,getdate())) Last_Price_Chng,ExtrnId,SvcProvSvcId from ##temp_CDMAllPrices group by ExtrnId,SvcProvSvcId) B 
    on A.ExtrnId = B.ExtrnId 
        AND A.SvcProvSvcId = B.SvcProvSvcId
        AND isnull(A.LastRateChange,getdate()) = B.Last_Price_Chng

DECLARE @FileLocation varchar(255)
DECLARE @OutputFile varchar(255)
DECLARE @FileName varchar(255)
DECLARE @strCommand varchar(8000)

SET @FileLocation = '\\server\LoadFiles\'
SET @OutputFile = 'ExperianCDM'
SET @FileName = @FileLocation + LTRIM(RTRIM(@OutputFile)) + '.txt'  
SET @strCommand = 'bcp "SELECT * from [server].[Database].[##temp_CDM]" queryout ' + @filename +' -t "|"  -c -T'

RAISERROR(@FileName, 0, 1) WITH NOWAIT
PRINT @strCommand

EXECUTE master.dbo.xp_cmdShell @strCommand

Drop Table ##temp_CDMAllPrices, ##temp_CDM
0

There are 0 best solutions below