Reputation: 3345
I am trying to construct a query where I check the number of rows returned from a sql select. For example, I want to check that if the number of rows returned from a query are greater than 3, then do something else do nothing
if @@rowcount(select clientId from Clients group by clientId) > 3
PRINT 'WARNING'
Any ideas appreciated
Upvotes: 1
Views: 594
Reputation: 368
Hope this helps
[EDITED]
DECLARE @Cnt AS INT
select @Cnt = COUNT(clientId) from Clients group by clientId
if @Cnt > 3
PRINT 'WARNING'
Upvotes: 1
Reputation: 280351
DECLARE @Count INT = (SELECT COUNT(DISTINCT ClientId) FROM Clients);
IF @Count > 3
PRINT 'WARNING';
Upvotes: 3
Reputation: 1893
Try:
case
when (select count(*) from table where condition) > 3 Then
else
end
Hope this helps...
Upvotes: 4