I want to know what does coalesce do in this case, I know it returns first non null value and I have gone through this link as well.
I want to know what does it do specifically here:
DECLARE @EMPNO NUMERIC(22,5)
SELECT @EMPNO = ''
SELECT @EMPNO = COALESCE(?, 0)
My intention in writing these statements is if @EMPNO is blank I want it to be replaced with zero instead. I’m afraid that I was able to achieve this out of these three statements.
Help me out
I think you have to do like this:
You know you can also write
You cannot set a
NUMERICto an empty varchar. You have to set it toNULL. So you full code should be like this:Or you do not even need the to set the
@EMPNOtoNULL. When you declare a variable it isNULLby default. So the only thing you need is this:If you read on msdn it says:
Reference here