Basically I have three fields and I am creating a new one which is three combined which use a mail address Does; Due to the problem, some fields have zero values and adding my string to a null only produces a blank in SQL
So this is my code, can someone make it cleaner? [Account] SET [Billing Street] = Case when [(Billing address 1)] is blank and [[Address of billing] 2)] is zero [(billing address 3)] when [[billing address 1]] is zero and [(Billing address 3)] is zero THIN [(billing address 2)] when [[billing address2]] is zero ([billing address 3]] is zero [(billing address 1)] when [(billing address 1 }] Is zero [[billing address 2]] + "" [[billing address 3]] WHEN [(billing address 2)] is zero [[billing address 1]] + "+ [(billing address 3)] When [[billing address 3]] is zero, [[billing address 1]] + '' + [( Ing address 2)] ELSE [(billing address 1)] + '' [(billing address 2]] + "+ [(billing address 3)] END
You can use isnull
and ltrim
to remove any leading whitespace: Update [mydb]. [DBO]. [Account] Set [BI] Lilling Street] = ltrim (isnull ([(billing address 1)], '') + isnull ('' [(Billing address 2)], '' + isnull ('' [[billing address 3]], ''))
Comments
Post a Comment