May 20, 2010 at 4:02 pm
We have daily batch processing system that loads about 7 mln records into a table with 130 columns. There are a lot of empty values, they are not null but just '' (zero-length strings).
We need to have something, default or anything except triggers, that would convert these '' into nulls when we load the data. Any ideas appreciated.
Thanks
May 20, 2010 at 4:13 pm
How about a simple update query add the end of the batch that updates the columns to NULL where value = ''?
May 20, 2010 at 5:44 pm
From a T-SQL standpoint you can do something like this:
update myTable
set Column1 = case Column1 when '' then null end,
Column2 = case Column2 when '' then null end,
Column3 = case Column3 when '' then null
where <some condition>
However, if possible, it would be better to transform '' to null in the course of the actual import, but the feasibility of doing that depends on the tool you are using for the import.
May 20, 2010 at 6:19 pm
Take a look in Books Online at the NULLIF() function. It may not help directly for the load into your staging table (you do have a staging table, I hope) but it will easily convert such empty strings to nulls during the transfer to the final table.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 20, 2010 at 9:04 pm
I know about an update query after the loading data, but this is my last resort if nothing else worked.
We don't have a staging table, the data is loaded from a text file using bcp/ bulk insert. I will also try to look into SSIS.
But probably the most elegant solution would be to do something while data is being bcp-ed. This is what I am trying to find.
May 20, 2010 at 10:44 pm
hello....
if u dont mind plz let me knw how u are loading the data through a wizard or through some scripts like vb script or bulk insert ... etc
so that we can find out a solution for it....
and the environment is it sql2005 or sql2008
May 21, 2010 at 7:31 am
No, we are not using wizard. The data is loaded with bcp / bulk insert. Version 2005
May 21, 2010 at 7:45 am
Have you looked into Jeff's suggestion yet?
NULLIF(MyDodgyColumn, '')
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply