存储过程:count(*)
select count(*) as total from TableName
把total的值提交到数据库中
这个存储过程如何写啊
------解决方案--------------------create procedure
select count(*) as total from TableName
------解决方案--------------------select count(*) as total from TableName
update TableName set TableName.total = (select count(*)from TableName)
------解决方案-------------------- "把total的值提交到数据库中 "
-------------------------------
是什么意思啊?
create proc up_test
as
insert into 表
select count(*) as total from TableName
------解决方案--------------------莫非你要这样的
CREATE TABLE DBO.[表]
(
total INT
)
CREATE PROC DBO.TEST
AS
SET NOCOUNT ON
BEGIN TRAN
INSERT INTO DBO.[表]
SELECT COUNT(*) AS TOTAL FROM DBO.TableName
IF @@ERROR <> 0
ROLLBACK TRAN
ELSE
COMMIT TRAN
GO
------解决方案--------------------有几种方法来实现
1.将查询结果插入一个表
insert into 表
select count(*) as total from TableName
2.将查询结果更新到一个表中
update 表 set 更新列 = (select count(*)from TableName)
--当然后面还可以加上Where语句
3.将查询结果赋值给一个变量,以做他用
Declare @iNumer int
Select @iNumer=Count(*) From from TableName
--此时可对变量@iNumer做其他操作
4.对于结果是否执行正确的判断
IF @@ERROR <> 0
--判断执行操作是否正确
IF @@ROWCOUNT> 0
--在判断行数是否大于0