--检查部位统计
CREATE PROCEDURE sp_BodypartGrpstats
    @ModalityType varchar(18), 
    @StatStartDttm datetime,
    @StatEndDttm datetime 
AS
BEGIN
 
DECLARE @sStudy_dttm datetime 
DECLARE @iStudy_key int
DECLARE @sGroupField varchar(128)
DECLARE @sStatistField varchar(128)
DECLARE @fStatistWeight money
DECLARE @iPos int
DECLARE @ilen int


DECLARE crStudy CURSOR FOR

SELECT study_dttm, study_key, study_bodypart
FROM study
WHERE study_modalitytype=@ModalityType AND report_state > 0 AND
	study_dttm >= @StatStartDttm AND study_dttm <= @StatEndDttm 

OPEN crStudy

FETCH NEXT FROM crStudy 
INTO @sStudy_dttm,@iStudy_key,@sGroupField

WHILE @@FETCH_STATUS = 0
BEGIN
  SET @sGroupField=RTRIM(LTRIM(@sGroupField))  
  IF LEN(@sGroupField) > 0
  BEGIN
	  SET @iPos=CHARINDEX(' ',@sGroupField)          
	  WHILE @iPos>=1       
	  BEGIN    
		SET @sStatistField=SUBSTRING(@sGroupField,1,@iPos-1)  
		INSERT INTO CC_Statist (study_dttm,statist_field,statist_weight)
			VALUES(@sStudy_dttm,@sStatistField,1)
		SET @iLen=LEN(@sGroupField)  
		SET @sGroupField=SUBSTRING(@sGroupField,@iPos+1,@iLen)  
		SET @sGroupField=RTRIM(LTRIM(@sGroupField))  
		SET @iPos=CHARINDEX(' ',@sGroupField)  
	  END

	  INSERT INTO CC_Statist (study_dttm,study_key,statist_field,statist_weight)
		VALUES(@sStudy_dttm,@iStudy_key,@sGroupField,1)    
  END
  	
  FETCH NEXT FROM crStudy 
  INTO @sStudy_dttm,@iStudy_key,@sGroupField 
END       

CLOSE crStudy     
DEALLOCATE crStudy 

-- 每个检查部位算一人次，没有权重差别

END