SQL Server : if…else based on row count

dominiccobra

New Member
This statement errors if there are no rows in the select statment (select top 1...)\[code\]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\[/code\]Is there a way to test the count of this statement and default to 1 if no records found?\[code\]select top 1 nPosition from tHomePageWorking where nColumn = 2 order by nPosition desc\[/code\]
 
Back
Top