SQL Server blank to numeric conversion derived column

jgovgodb  于 2023-06-21  发布在  其他
关注(0)|答案(3)|浏览(154)

I have a source column with blank (not "NULL"), and target as numeric. while converting using the data conversion it is not converting due to balnk source value so I used derived column to replace a blank value with NULL or 0 as

(source column == " ") ? "0" : source column

but its not giving the value as 0 in the blank place.

thanks prav

kiayqfof

kiayqfof1#

This should do the trick.

(LEN(TRIM(sourceColumn)) = 0 ? "0" : sourceColumn)
guicsvcw

guicsvcw2#

([source column] == null || [source column].TrimEnd().Length == 0)
     ? "0"
     : [source column]
kgsdhlau

kgsdhlau3#

I'm pretty sure that the codingbadger answer is missing 1 =. I used that answer but to make it valid I had to write it as:

(LEN(TRIM(sourceColumn)) == 0 ? "0" : sourceColumn)

相关问题