Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Translate Access code to T-SQL

Status
Not open for further replies.

Stickarm

Programmer
Jun 20, 2001
72
US
I am trying to link an Access Database to some SQL tables and I need to translate some code into a stored procedure.

I am having problems translating the I statements into a proper t-SQL format. I am stuck on how to do and update and set statement with an IF THEN or CASE statement embedded. Please help..
The code in bold is code taken from the Access database

CREATE PROCEDURE sp_CompAssess
AS
update TMultExam
set

If TMaster.MeasurableProd > 0 Then
AssessedDollars = (TMaster.MeasurableProd * Percentage) / 100
Else
AssessedDollars = ((TMaster.Tax + TMaster.Penalty + TMaster.Interest) * Percentage)/100
End If
AuditCount = (Percentage * TMaster.AudCount) / 100


from tmultExam, Tmaster
Where TMaster.RecordNumber = TMultExam.RecordNumber


 

I'd rewrite the code in this way.

CREATE PROCEDURE sp_CompAssess AS
UPDATE TMultExam
SET AssessedDollars=
CASE
WHEN TMaster.MeasurableProd > 0 Then (TMaster.MeasurableProd * Percentage) / 100
ELSE ((TMaster.Tax + TMaster.Penalty + TMaster.Interest) * Percentage)/100
END,
AuditCount = (Percentage * TMaster.AudCount) / 100
FROM tmultExam INNER JOIN Tmaster
ON TMultExam.RecordNumber = TMaster.RecordNumber
Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top