I doubt "EXEC sp_MSForEachTable" solution will not work, assuming the database has few more table, which don't have that User Id column, unless you are explicitly handling such failure using try catch block. In that case It will surely fail.
Here the solution to consider only those table which have the required column.
--To get the List of Table having the required column and Storing them into Temp Table.
Select ID = IDENTITY(Int,1,1),Object_Name(object_id) As TableName Into #ReqTables
From sys.columns where name = 'Crets'
--Creating Table to Store Row count result.
Create Table #RowCounts
(
Row_Count Int
, UserID Int
)
--Declaring variables
Declare @min Int,@max int,@TableName Nvarchar(255)
--get min and Max values from Required table for looping
Select @min = Min(Id),@max = Max(ID) From #ReqTables
--loop through Min and Max
While(@min <= @max)
BEgin
--get the table for a given loop Counter
Select @TableName = tableName From #ReqTables Where Id = @min
--Executing the Dynamic SQl
Exec ('Insert Into #RowCounts (Row_Count,UserID) Select Count(*),UserID From ' + @TableName + ' Group by UserID')
--incrementing the Counter
Set @min = @min + 1
End
SUM()notGROUP BY.... But thenSUM()usesGROUP BY, so you're ultimately right :-)