doctor069
asked on
sql cte rowcount
Hi I have a simple cte but I need to check to see if it returns any rows
Please see my code below. It seems that I can't put an "If" after the CTE. I get a syntax error
Thanks in advance
Please see my code below. It seems that I can't put an "If" after the CTE. I get a syntax error
Thanks in advance
WITH Photos AS
(
SELECT ROW_NUMBER() OVER(Order by [CreatedDate] DESC) as RowNum
,[id]
,[CreatedDate]
,[ImageTitle]
,COUNT([id]) OVER () AS [totalRows]
FROM [dbo].[Photos]
where
[UserId] = @Userid
)
IF @@ROWCOUNT = 0
BEGIN
PRINT 'No Photos'
END
ELSE
PRINT 'Has photos'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER