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


Replace NULL with empty space.


Replace NULL with empty space.

Author
Message
HBK_4700
HBK_4700
Old Hand
Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)

Group: General Forum Members
Points: 364 Visits: 1821
I am trying to export the SQL Server 2005 database tables(10) to csv files.

But some of the tables columns data have NULL values. I need to replace the NULL values with empty space. Easy way to find and replace in csv file.

I tried to write the T-sql statement using ISNULL function. But I could see 0 in NULL place.

Is there any way in SSIS where I can get it done? Appriciate your help.
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21157 Visits: 18259
what was the statement that you used for isnull?

What is the datatype that has null values in the database?



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45464 Visits: 39948
laddu4700 (9/16/2010)
I am trying to export the SQL Server 2005 database tables(10) to csv files.

But some of the tables columns data have NULL values. I need to replace the NULL values with empty space. Easy way to find and replace in csv file.

I tried to write the T-sql statement using ISNULL function. But I could see 0 in NULL place.

Is there any way in SSIS where I can get it done? Appriciate your help.


You'll need to convert all numerics to strings if you want ISNULL(somenumber,'') to actually convert to an empty space.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
HBK_4700
HBK_4700
Old Hand
Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)

Group: General Forum Members
Points: 364 Visits: 1821
I used below query

USE dbname;
GO
select column1, column2, ISNULL(Column3, ' ') AS 'xxxx'
FROM Table1;
GO


column3 (FK, int, null)
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21157 Visits: 18259
Jeff's response should help you fix that. You can use the convert function in TSQL to change the int data type to a varchar or char (string) datatype so you can display an empty string rather than a 0.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16548 Visits: 13210
CirquedeSQLeil (9/16/2010)
Jeff's response should help you fix that. You can use the convert function in TSQL to change the int data type to a varchar or char (string) datatype so you can display an empty string rather than a 0.


And to be complete so the OP knows why this is happening: an empty string is converted to a 0 when you cast it to an int.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
HBK_4700
HBK_4700
Old Hand
Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)

Group: General Forum Members
Points: 364 Visits: 1821
I created below script and added to source in SSIS package, destination I have taken csv file.
when I execute the package I am getting below error.
Column 'OfficePhone' cannot convert between unicode and non-unicode string data types

SELECT [UserID]
,[UserName]
,ISNULL(Cast(OfficePhone AS VARCHAR(10)), '') AS 'OfficePhone'
,ISNULL(Cast(OfficeFax AS VARCHAR(10)), '') AS 'OfficeFax'
,CONVERT(varchar(10), DateCreated, 110) + SUBSTRING(CONVERT(varchar, DateCreated,
109), 12, 9) + SUBSTRING(CONVERT(varchar, DateCreated, 109),25,2)as DateCreated
,CONVERT(varchar(10), ModifiedDate, 110) + SUBSTRING(CONVERT(varchar, ModifiedDate,
109), 12, 9) + SUBSTRING(CONVERT(varchar, ModifiedDate, 109),25,2)as ModifiedDate
,[UserZipcode]
FROM [DBName].[dbo].[Table1]

Please advice,whether I need to add a transformation to get it done.
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21157 Visits: 18259
Yes, I would add a transformation task and include all of the columns in this case.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

HBK_4700
HBK_4700
Old Hand
Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)

Group: General Forum Members
Points: 364 Visits: 1821
CirquedeSQLeil (9/17/2010)
Yes, I would add a transformation task and include all of the columns in this case.


Thanks for your reply. Can you please explain in details, what transformation need to add and how to map.
Kind of new to SSIS packages. Appreciate your help.
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21157 Visits: 18259
Try this as a starting point
http://www.bimonkey.com/2009/06/the-data-conversion-transformation/



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

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