我需要使用如下所示的存储过程将数据插入另一个表:
CREATE PROCEDURE T.countnum
AS
Insert into T1 values(select count(*) from T.countTable)
但它不起作用我看到了几个例子,但没有选择。有什么例子吗?
我需要使用如下所示的存储过程将数据插入另一个表:
CREATE PROCEDURE T.countnum
AS
Insert into T1 values(select count(*) from T.countTable)
但它不起作用我看到了几个例子,但没有选择。有什么例子吗?
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
use db;
CREATE PROCEDURE T.countnum
AS
Insert into T1 values((select count(*) from T.countTable))
go
你可以试试:
Insert into T1(CountColumn)
select count(*) from T.countTable
这是语法:
INSERT INTO MyTable
(
Column1,
Column2
)
EXEC [dbo].[yourStoredProcName]