From: | "Ehmann, Mary" <butlerme(at)msx(dot)upmc(dot)edu> |
---|---|
To: | "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org> |
Subject: | |
Date: | 2003-02-07 19:00:35 |
Message-ID: | 328D53D0EEF7D411822900508B6FDDE607F9B388@1upmc-msx2.isdip.upmc.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Could someone please tell me why this is scoring all BUT my first row of
data?
Thank you.
CREATE PROCEDURE scoreBDI_sp AS
DECLARE X CURSOR
for SELECT * FROM BDI
DECLARE @STUDYID int
DECLARE @ADATE datetime
DECLARE @TPOINT smallint
DECLARE @PORC nvarchar
DECLARE @FNAME nvarchar
DECLARE @LNAME nvarchar
DECLARE @BDI1 smallint
DECLARE @BDI2 smallint
DECLARE @BDI3 smallint
DECLARE @BDI4 smallint
DECLARE @BDI5 smallint
DECLARE @BDI6 smallint
DECLARE @BDI7 smallint
DECLARE @BDI8 smallint
DECLARE @BDI9 smallint
DECLARE @BDI10 smallint
DECLARE @BDI11 smallint
DECLARE @BDI12 smallint
DECLARE @BDI13 smallint
DECLARE @BDI14 smallint
DECLARE @BDI15 smallint
DECLARE @BDI16 smallint
DECLARE @BDI17 smallint
DECLARE @BDI18 smallint
DECLARE @BDI19 smallint
DECLARE @BDI20 smallint
DECLARE @BDI21 smallint
DECLARE @TOTAL float
DECLARE @NUMANS float
DECLARE @BDITOT float
DECLARE @CLEANED char
DECLARE @NEW char
SET @TOTAL=0
SET @BDITOT=0
SET @NUMANS=0
OPEN X
FETCH NEXT FROM X INTO @STUDYID, @ADATE, @TPOINT, @PORC, @FNAME, @LNAME,
@BDI1, @BDI2, @BDI3, @BDI4, @BDI5, @BDI6, @BDI7, @BDI8, @BDI9, @BDI10,
@BDI11, @BDI12, @BDI13, @BDI14, @BDI15, @BDI16, @BDI17, @BDI18, @BDI19,
@BDI20, @BDI21, @TOTAL, @NUMANS, @BDITOT, @CLEANED, @NEW
WHILE (@@FETCH_status=0) BEGIN
IF @BDI1 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI1
SET @NUMANS=(at)NUMANS+1
END
IF @BDI2 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI2
SET @NUMANS=(at)NUMANS+1
END
IF @BDI3 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI3
SET @NUMANS=(at)NUMANS+1
END
IF @BDI4 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI4
SET @NUMANS=(at)NUMANS+1
END
IF @BDI5 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI5
SET @NUMANS=(at)NUMANS+1
END
IF @BDI6 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI6
SET @NUMANS=(at)NUMANS+1
END
IF @BDI7 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI7
SET @NUMANS=(at)NUMANS+1
END
IF @BDI8 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI8
SET @NUMANS=(at)NUMANS+1
END
IF @BDI9 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI9
SET @NUMANS=(at)NUMANS+1
END
IF @BDI10 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI10
SET @NUMANS=(at)NUMANS+1
END
IF @BDI11 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI11
SET @NUMANS=(at)NUMANS+1
END
IF @BDI12 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI12
SET @NUMANS=(at)NUMANS+1
END
IF @BDI13 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI13
SET @NUMANS=(at)NUMANS+1
END
IF @BDI14 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI14
SET @NUMANS=(at)NUMANS+1
END
IF @BDI15 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI15
SET @NUMANS=(at)NUMANS+1
END
IF @BDI16 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI16
SET @NUMANS=(at)NUMANS+1
END
IF @BDI17 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI17
SET @NUMANS=(at)NUMANS+1
END
IF @BDI18 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI18
SET @NUMANS=(at)NUMANS+1
END
IF @BDI19 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI19
SET @NUMANS=(at)NUMANS+1
END
IF @BDI20 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI20
SET @NUMANS=(at)NUMANS+1
END
IF @BDI21 <> 999
BEGIN
SET @TOTAL=(at)TOTAL+@BDI21
SET @NUMANS=(at)NUMANS+1
END
IF @NUMANS > 16
BEGIN
SET @BDITOT= round(@TOTAL * (21.0
/@NUMANS),0)
END
ELSE
BEGIN
SET @BDITOT=999
END
update BDI set BDITOT=(at)BDITOT, TOTAL=(at)BDITOT, NUMANS=(at)NUMANS, NEW='N' WHERE
[ID]=(at)studyid and ADATE=(at)adate and TPOINT=(at)TPOINT AND PORC=(at)PORC
fetch next from X into @STUDYID, @ADATE, @TPOINT, @PORC, @FNAME, @LNAME,
@BDI1, @BDI2, @BDI3, @BDI4, @BDI5, @BDI6, @BDI7, @BDI8, @BDI9, @BDI10,
@BDI11, @BDI12, @BDI13, @BDI14, @BDI15, @BDI16, @BDI17, @BDI18, @BDI19,
@BDI20, @BDI21, @TOTAL, @NUMANS, @BDITOT, @CLEANED, @NEW
SET @TOTAL=0
SET @NUMANS=0
END
CLOSE X
DEALLOCATE X
From | Date | Subject | |
---|---|---|---|
Next Message | Luis Magaña | 2003-02-07 20:57:58 | Start and End Day of a Week |
Previous Message | Steve Crawford | 2003-02-07 18:54:32 | Re: bytea |