0

我需要使用如下所示的存储过程将数据插入另一个表:

CREATE PROCEDURE T.countnum
AS
   Insert into T1 values(select count(*) from T.countTable)

但它不起作用我看到了几个例子,但没有选择。有什么例子吗?

4

4 回答 4

1
use db;
CREATE PROCEDURE T.countnum
AS
Insert into T1 ([column_name])
select count(*) 
from T.countTable
go

或者

use db;
CREATE PROCEDURE T.countnum
AS

declare @counting int

select @counting = count(*) 
from T.countTable

Insert into T1 ([column_name]) values (@counting)

go

你应该指定要计数的列select count(id) from T.countTable

于 2012-05-30T07:07:26.613 回答
1
use db;
CREATE PROCEDURE T.countnum
AS
Insert into T1 values((select count(*) from T.countTable))
go
于 2012-05-30T07:29:21.163 回答
0

你可以试试:

Insert into T1(CountColumn) 
select count(*) from T.countTable
于 2012-05-30T07:05:03.853 回答
0

这是语法:

INSERT INTO MyTable  
(  
    Column1,  
    Column2  
)  
EXEC [dbo].[yourStoredProcName]
于 2012-05-30T07:07:11.047 回答