You can try this following:
declare @rent decimal
set @rent = 1000
--select format(@rent,'C0')
select
case
when ISNULL(CAST(@rent AS varchar(50)),'') = '' then NULL
-- I have used NULL as if the value = '' then it should be
-- presented by Null which is allowed for all data type
else cast(format(@rent,'C') as varchar(50))
end AS Rent
In fact you can directly use the formatting as below as if the input is NULL
, it will automatically return NULL
. No need to go through a CASE
expression.
declare @rent decimal
--set @rent = 1000
--select format(@rent,'C0')
select cast(format(@rent,'C') as varchar(50)) AS Rent