sql2005 定义临时表

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 @Table table(Person_ID int)

 

insert into @Table(Person_ID)

select Person_ID from PersonInfo where Family_ID=@Family_ID

 

select Sum(P.SmokeCount) as TotleSmokeCount from @Table T left join PersonActionInfo P on T.Person_ID=P.Person_ID

原文地址:https://www.cnblogs.com/zhc088/p/860152.html