I have a table with a non-null field I wish to populate from another table. Trouble is the query into the other table may return null. How do I get a value (0 will do) when the query returns null? My query is:
update Packages
set PackageTypeId = (SELECT TOP 1 PackageTypeId
FROM PackageTypes
WHERE Packages.PackageTypeName = PackageTypes.Name
ORDER BY PackageTypeId ASC)
I tried using coalesce, but it still fails:
update Packages
set PackageTypeId = (SELECT TOP 1 coalesce(PackageTypeId, 0) as id
FROM PackageTypes
WHERE Packages.PackageTypeName = PackageTypes.Name
ORDER BY PackageTypeId ASC)
Any ideas?