J. Davidson
J. Davidson

Reputation: 3307

Replacing null with zero

Hi I have following select command in SQL Server. I am trying to change it so if b.bId is null i want to assign it 0 value. So it displays 0 in the field.

select top 1
    a.sId
   ,b.bId  
    from tlocal a
    left outer join ts b on (b.id=a.mainId)
    where 
    a.id=@xId; 

Please let me know how to modify. Thanks

Upvotes: 2

Views: 3368

Answers (3)

very9527
very9527

Reputation: 959

As another alternative you could execute this sql at your ts table

update ts
set id = ''
where id is null

Upvotes: 3

Mark Kram
Mark Kram

Reputation: 5832

Or you can use the COALESCE Function

COALESCE(b.bId, 0) AS bId

Performance: ISNULL vs. COALESCE

Upvotes: 4

ermagana
ermagana

Reputation: 1230

You can use the ISNULL function like so:

ISNULL(b.bId, 0) bId

Upvotes: 6

Related Questions