日期:2014-05-18  浏览次数:20475 次

求叫一个简单的存储
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= '+@companyname        
  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 companyname=@companyname
return
go