Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

SELECT .. INTO to replace empty string or NULL value

$
0
0
I need a sanity check on some code I've written.I have a large table (more than 100 million rows) that needs an update on several columns. I decided to build a new table using SELECT .. INTO rather than run an UPDATE statement. SELECT [Column1], [Column2], CASE [Column3] WHEN '' THEN 0 WHEN NULL THEN 0 ELSE [Column3] END AS 'Column3', [Column4]INTO [dbo].[Table_Update]FROM [dbo].[Table];The statement runs without error, but when I query the new table I do not see the results I expect to see.When I query the original table, I get a count of 8,390 records in which Column3 = ''. I expected to get zero rows when I query the new table for records in which Column3 = '', but instead I get the same count as before. Yet, when I query the new table for records in which Column3 = '', I see the 0 that I inserted into Column3 of the new table.Why do I get these results when it appears that my update succeeded?

Viewing all articles
Browse latest Browse all 3145

Latest Images

Trending Articles



Latest Images