LoginSignup
1
1

More than 5 years have passed since last update.

NULLと空文字列が混在したカラムをどちらかで統一したい

Posted at

サンプルテーブル

CREATE TABLE #Sample (col1 char(1));
INSERT INTO #Sample (col1) VALUES ('A'), (NULL), ('');
col1
'A'
NULL
''

NULLで統一

UPDATE #Sample
   SET col1 = CASE WHEN col1 = '' THEN NULL ELSE col1 END;
col1
'A'
NULL
NULL

空文字列で統一

UPDATE #Sample
   SET col1 = COALESCE(col1, '');
col1
'A'
''
''
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1