Sql 表中的条件插入

Sql 表中的条件插入,sql,sql-server,tsql,Sql,Sql Server,Tsql,如果计数大于10,我将尝试在表中插入一些数据。我的示例代码在这里 IF EXISTS (select * from tbl1) BEGIN select e.UserId, count(*) as [Registrations], 'qq' = case when count(*) < 10 then 'less than 10' when count(*) > 10 then 'more than 10' e

如果计数大于10,我将尝试在表中插入一些数据。我的示例代码在这里

IF EXISTS (select * from tbl1) 
BEGIN
   select e.UserId, count(*) as [Registrations], 'qq' = 
       case 
        when count(*) < 10 then 'less than 10'
        when count(*) > 10 then 'more than 10' 
       end
    from tbl1 as e group by e.UserId
END
ELSE
BEGIN
   select * from tbl2
END
当计数*大于10时,如何将begin insert tbl2值1,'2013-01-31 19:08:19.847'结束

不允许直接插入我无法将插入赋值给变量


这是我的计数结果*

,正如Veljko89所写的那样-您可以在GROUP BY之后使用HAVING,并将其选择到临时表中。然后,您可以使用此临时表来决定何时/何时插入第二个表。

您指的是什么计数*?示例数据和所需结果很有用。@如果从tbl1>10@GordonLinoffcount*是整行。例如,它返回37 1 2 69 22等@George Count*是一个整数值。你能解释一下你所说的整行是什么意思吗?如果我正确理解你的要求,你的“真实条件”中的select应该有“HAVING COUNT*>10”子句