【发布时间】:2022-12-27 20:22:44
【问题描述】:
I'm importing a lot of data from an excel file using the SSIS package. Thus, Excel contains some empty columns. I'd like to make it Null.
I'm now updating a blank column to NULL using the query below.
UPDATE TT
SET DEATHDATE = NULL
FROM TEMP_TABLE TT
WHERE LTRIM(RTRIM(DEATHDATE)) = ''
UPDATE TT
SET CURRENTDATE= NULL
FROM TEMP_TABLE TT
WHERE LTRIM(RTRIM(CURRENTDATE)) = ''
UPDATE TT
SET City = NULL
FROM TEMP_TABLE TT
WHERE LTRIM(RTRIM(City )) = ''
OR
UPDATE TT
SET BIRTHDATE = NULL
FROM TEMP_TABLE TT
WHERE DATALENGTH(BIRTHDATE) = 0
This update statement will update toNULLif the specified column records areEMPTY.
But I don't like doing this. I want to change all of the records in the table. If there areEMPTYrecords in that table, I want to change them toNULL.
Is that even possible? Thank you in advance
【问题讨论】:
-
You have to specify each column you want to update. And I'd probably do a separate UPDATE for each column.
-
Why are these apparent dates even strings?
-
@HoneyBadger I'm using the SSIS package to import data from an excel file. so i import the date types as NVARCHAR
标签: sql sql-server