declare @tab table
(
id int,
name nvarchar(50)
)
insert into @tab(id,name)
select person_id,1 from personinfo
select * from @tab
------------------------------------------------------------------ ----------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Jack zhang>
-- Create date: <2007-08-04>
-- Description: <获取家庭吸烟总量(创建表变量)>
-- =============================================
ALTER PROCEDURE [dbo].[Family_SmokeTotal]
(@Family_ID int)
AS
declare @tab table(Person_ID int)
insert into @tab(Person_ID)
select Person_ID from PersonInfo where Family_ID=@Family_ID
select Sum(SmokeCount) '家庭吸烟总数' from PersonActionInfo where Person_id in (select Person_id from @tab)
//临时表
CREATE TABLE #tmp
(
rq NVARCHAR(10),
shengfu NVARCHAR(1)
)
INSERT into #tmp select'2005-05-09','胜'
Insert into #tmp select'2005-05-09','胜'
insert into #tmp select'2005-05-09','负'
insert into #tmp select'2005-05-09','负'
insert into #tmp select'2005-05-10','胜'
insert into #tmp select'2005-05-10','负'
insert into #tmp select'2005-05-10','负'
SELECT rq,sum(case when shengfu='胜' then 1 else 0 end)'胜',sum(case when shengfu='负' then 1 else 0 end)'负'
from
#tmp
group by rq
用临时表吧
create table #table(id int identity(1,1),tid int)
insert into #table
values(1)
select * from #table
drop table #table
go
create table #table(id int identity(1,1),tid int)
insert into #table
values(1)
select * from #table
drop table #table