当前位置: 代码迷 >> Sql Server >> 求叫一个简单的存储,该如何处理
  详细解决方案

求叫一个简单的存储,该如何处理

热度:8   发布时间:2016-04-27 16:52:07.0
求叫一个简单的存储
create   proc   Statistic
@companyname   nvarchar(100),
@total_company   int=0   output
as
declare  
@countcompany   nvarchar(10)

set   @countcompany= 'select   @a1=count(1)   from   company   where         companyname= '[email protected]        
  exec   sp_executesql   @countcompany   ,N '@a1   int   output ',@total_company   output
大家看看有什么问题,
执行后结果总为0


------解决方案--------------------
create proc Statistic
@companyname nvarchar(100),
@total_company int=0 output
as
begin
declare @countcompany nvarchar(10)

set @countcompany=N 'select @a1=count(1) from company where companyname= ' ' ' + @companyname + ' ' ' '

exec sp_executesql @countcompany ,N '@a1 int output ',@total_company output
end
go
------解决方案--------------------
--try

create proc Statistic
@companyname nvarchar(100),
@total_company int output
as
select @total_company=count(1) from company
where [email protected]
return
go
  相关解决方案