<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1126" name=GENERATOR>
<STYLE>@font-face {
font-family: Tahoma;
}
@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.25in 1.0in 1.25in; }
P.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
LI.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
DIV.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
A:link {
COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
FONT-WEIGHT: normal; COLOR: windowtext; FONT-STYLE: normal; FONT-FAMILY: Tahoma; TEXT-DECORATION: none
}
DIV.Section1 {
page: Section1
}
</STYLE>
</HEAD>
<BODY lang=EN-US vLink=purple link=blue bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Arthur's task list for porting such code to
sprocs:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>1. Identify each recordset and create a
corresponding view or UDF that returns the identical result set.</FONT></DIV>
<DIV><FONT face=Arial size=2>2. Create one or more SELECT statements that join
these views|UDFs the way you need them joined. now you have some reusable
components.</FONT></DIV>
<DIV><FONT face=Arial size=2>3. Combine these reusable components in a SELECT
statement that gives you all the rows you need and only those rows. Save this to
a new view or UDF.</FONT></DIV>
<DIV><FONT face=Arial size=2>4. Consider passing parameters that are defaulted.
The way you've written the code, you walk the entire outermost table (tblClaims)
without investigating whether or not there exist child rows. In a stored
procedure, you can specify a parameter and give it a default value -- then react
to its value within your sproc code. For example, your sproc might accept a
parameter @ClaimNo whose default is zero; in the event that @ClaimNo = 0,
process all Claims; else process only the specified ClaimNo. This will result in
dramatically faster execution in most situations. </FONT></DIV>
<DIV><FONT face=Arial size=2>5. To make all this work from an ADP, you will need
to investigate command and parameter objects. This stuff is not difficult, but
if you need some help I will supply some sample code.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>At the end of the day, you're updating a few rows
in one table. When you move from recordset code to resultset code, the first
thing you should kiss goodbye is the notion of a row. (I realize that is a very
general statement, but its exceptions are few and typically reflect a bad
database design rather than a need to sharpen set code to row
code.)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Just my $.02.</FONT></DIV>
<DIV><FONT face=Arial size=2>A.</FONT></DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=MarkBoyd@mcbeeassociates.com
href="mailto:MarkBoyd@mcbeeassociates.com">Mark Boyd</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=AccessD@databaseadvisors.com
href="mailto:AccessD@databaseadvisors.com">AccessD@databaseadvisors.com</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, February 03, 2003 9:39
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [AccessD] Creating a stored
procedure</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Cross-posted to SQLServer
list.</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Let me start out by stating that
I am totally novice to creating stored procedures.</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">I hope someone can help me to
create my first stored proc.</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">I have the VBA code complete, but
am having trouble converting to the proc.</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">The code is
below:</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">Set rst = db.OpenRecordset("SELECT
* FROM tblClaim ORDER BY ClaimNo", dbOpenDynaset,
dbSeeChanges)</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">rst.MoveFirst</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">Do Until rst.EOF =
True</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
Me.txtStatus = "Processing record " & rst!PatientNo</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
Me.Repaint</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
curPaidAmt = 0</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
curCharge = 0</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
intClaimNo = rst!ClaimNo</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
intReferral = Nz(rst!Referral)</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
strProvNo = rst!ProvNo</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> Set
rstPrint = db.OpenRecordset("SELECT * FROM tblPrintCharges WHERE ClaimNo = "
& intClaimNo & "")</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> If
rstPrint.EOF = False Then</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPrint.MoveFirst</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
Do Until rstPrint.EOF = True</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rst.Edit</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rst!PaidAmt = Nz(rst!PaidAmt) + Nz(rstPrint!PaidAmt)</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
curPaidAmt = Nz(curPaidAmt) + Nz(rstPrint!PaidAmt)</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rst!TotalClaimAmt = Nz(rst!TotalClaimAmt) +
Nz(rstPrint!Charge)</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
curCharge = Nz(curCharge) + Nz(rstPrint!Charge)</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rst.Update</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPrint.MoveNext</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
</SPAN></FONT><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">Loop</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> End
If</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> Set
rstPhy = db.OpenRecordset("SELECT * FROM tblCodPhy WHERE Referral = " &
intReferral & " AND ProvNo = '" & strProvNo &
"'")</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> If
rstPhy.EOF = False Then</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy.MoveFirst</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
Do Until rstPhy.EOF = True</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy.Edit</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy!ClaimPaid = "CP"</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy!ClaimPaidDate = Int(Now())</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy!ClaimPaidAmt = Nz(rstPhy!ClaimPaidAmt) +
Nz(curPaidAmt)</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy!ClaimChargeAmt = Nz(rstPhy!ClaimChargeAmt) +
Nz(curCharge)</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy.Update</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy.MoveNext</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
</SPAN></FONT><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">Loop</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> End
If</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
curPaidAmt = 0</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
curCharge = 0</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
curTotalCharges = 0</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
'Get total claim charge amounts per referral</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> Set
rstPhy = db.OpenRecordset("SELECT * FROM tblCodPhy WHERE Referral = " &
intReferral & "")</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> If
rstPhy.EOF = False Then</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy.MoveFirst</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
Do Until rstPhy.EOF = True</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
curTotalCharges = Nz(curTotalCharges) +
Nz(rstPhy!ClaimChargeAmt)</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rstPhy.MoveNext</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
</SPAN></FONT><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">Loop</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> End
If</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
DoCmd.RunSQL ("UPDATE tblCod SET CaseCost = UBTotal + " & curTotalCharges
& " WHERE Referral = " & intReferral & "")</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
rst.MoveNext</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma"> </SPAN></FONT><FONT
face=Tahoma size=1><SPAN
style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">Loop</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">I’m not exactly sure which
sections to include in the proc. Should I include the whole thing?
</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">How do I create a Do Loop in the
proc?</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Any help/direction is greatly
appreciated.</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Thanks,</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Mark Boyd</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">Sr. Systems
Analyst</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">McBee Associates,
Inc</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Tahoma size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma"></SPAN></FONT> </P></DIV></BLOCKQUOTE></BODY></HTML>