ICU 是一种说不出的痛啊

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
USE [Nursing] GO
 
/****** Object:  StoredProcedure [dbo].[P_GetICUVitualSign]    Script Date: 05/21/2015 21:47:21 ******/ SET ANSI_NULLS ON GO
 
SET QUOTED_IDENTIFIER ON GO
 
CREATE PROCEDURE [dbo].[P_GetICUVitualSign]   @VisitNumberParam varchar (30),   @RecordTypeParam datetime AS BEGIN
 
 SELECT into #temp   FROM [Nursing].[dbo].[V_ICUVitualSign]   where VisitNumber=@VisitNumberParam   order by RecordTime   -----------------------2----------------- create table #tempdata (   visitnumber varchar(30),   recordtime datetime,   code varchar(100),   value varchar(100) )
 
create table #tempdata2 (   rowindex int,   visitnumber varchar(30),   recordtime datetime,   code varchar(100),   value varchar(100) ) -----------------------3----------------- declare mycursor cursor for select VisitNumber,ItemNo,Value,RecordTime from #temp
 
declare @VisitNumber varchar(100) declare @ItemNo varchar(100) declare @Value varchar(100) declare @RecordTime datetime
 
open mycursor
 
FETCH next from mycursor into @VisitNumber,@ItemNo,@Value,@RecordTime
 
if @ItemNo=0 begin  insert into #tempdata2(rowindex,visitnumber,code,value)  select pos as rowindex, @VisitNumber as visitnumber,    nvalue as code ,'' as value   from Nursing.dbo.SplitToTable(@Value) where LEN(nvalue)>0 end
 
while @@FETCH_STATUS=0 begin
 
FETCH next from mycursor  into  @VisitNumber,@ItemNo,@Value,@RecordTime
 
declare @count int select @count=COUNT(1) from #tempdata2
 
if(@ItemNo=0)   begin   delete from #tempdata2   insert into #tempdata2(rowindex,visitnumber,code,value)   select  pos as rowindex,  @VisitNumber as visitnumber,     nvalue as code ,'' as value   from Nursing.dbo.SplitToTable(@Value) where LEN(nvalue)>0   end else begin  if(@count>0)   begin     delete from #tempdata where recordtime=@RecordTime     insert into #tempdata(   visitnumber,   recordtime ,   code ,   value )  select       a.visitnumber as visitnumber,    b.recordtime as recordtime ,    a.code as code ,    b.value  as value    from #tempdata2  as a left join       (select   pos as rowindex,    @RecordTime as recordtime,   nvalue as value   from Nursing.dbo.SplitToTable(@Value) where LEN(nvalue)>0) as b    on a.rowindex=b.rowindex   end end end
 
close mycursor DEALLOCATE mycursor -----------------------return data-----------------
 
  select    ltrim(rtrim(visitnumber)) as visitnumber,      recordtime as recordtime,      ltrim(rtrim(code )) as code,      ltrim( rtrim( value )) as value    from #tempdata  where recordtime=@RecordTypeParam   ------------------------------over-----------------   drop table #temp   drop table #tempdata   drop table #tempdata2  END
 
GO

 

posted @   iFreeSoft  阅读(169)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示