This statement errors if there are no rows in the select statment (select top 1…)
update tHomePageWorking
set nColumn = 2,
nPosition = ((select top 1 nPosition
from tHomePageWorking
where nColumn = 2
order by nPosition desc) + 1
)
where nPosition = 1 and nColumn = 1
Is there a way to test the count of this statement and default to 1 if no records found?
select top 1 nPosition
from tHomePageWorking
where nColumn = 2
order by nPosition desc
I think the COALESCE function wil lsolve your problem.
It will return the first non-null argument: