日期:2014-05-17 浏览次数:20713 次
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CarVehicleData_tbl_GetMaxData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[CarVehicleData_tbl_GetMaxData] GO ------------------------------------ --用途:查询记录信息 --项目名称: --说明: --时间:2012/5/12 15:37:58 ------------------------------------ CREATE PROCEDURE CarVehicleData_tbl_GetMaxData @C_ID int AS select top 1000 * into #temp from [CarVehicleData_tbl] where c_id = @c_id order by [CSN_UpdateTime] desc select c_id,[CSN_Part],CSN_NumberDataOriginal = max(case csn_type when 0 then [CSN_DataOriginal] end),CSN_NumberUpdateTime = max(case csn_type when 0 then [CSN_UpdateTime] end),CSN_StatusDataOriginal = max(case csn_type when 1 then [CSN_DataOriginal] end),CSN_StatusDataUpdateTime = max(case csn_type when 1 then [CSN_UpdateTime] end) from (select *,(select top 1 [CSN_DataOriginal] from #temp a where b.csn_updateTime = a.csn_updateTime and b.csn_type = a.csn_type and b.csn_part = a.csn_part and a.C_ID = @C_ID order by csn_updateTime desc) as [CSN_DataOriginal] from (select max([CSN_ID]) as [CSN_ID],c_id,[CSN_Part],[CSN_Type],max([CSN_UpdateTime]) as [CSN_UpdateTime] from #temp c group by c_id,[CSN_Part],[CSN_Type]) b) d group by c_id,[CSN_Part] drop table #temp GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CarVehicleData_tbl_GetMaxData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[CarVehicleData_tbl_GetMaxData] GO ------------------------------------ --用途:查询记录信息 --项目名称: --说明: --时间:2012/5/12 15:37:58 ------------------------------------ CREATE PROCEDURE CarVehicleData_tbl_GetMaxData @C_ID int AS select top 1000 * into #temp from [CarVehicleData_tbl]