Click here to Skip to main content
15,916,600 members
Home / Discussions / Database
   

Database

 
GeneralRe: How to find table in Access databse??? Pin
S Douglas21-Oct-05 0:19
professionalS Douglas21-Oct-05 0:19 
QuestionList of databases on mySQL server Pin
Golden Dragon9-Oct-05 14:08
Golden Dragon9-Oct-05 14:08 
QuestionMySQL - delete current row Pin
Junyor9-Oct-05 11:50
Junyor9-Oct-05 11:50 
Questionperformance? Pin
hassan azizi8-Oct-05 17:03
hassan azizi8-Oct-05 17:03 
QuestionSystem DB Pin
Ranoush7-Oct-05 21:55
Ranoush7-Oct-05 21:55 
AnswerRe: System DB Pin
S Douglas20-Oct-05 23:33
professionalS Douglas20-Oct-05 23:33 
QuestionGenerate Create Script will not show up in Database Project in VS.NET Pin
Pitchiah4u7-Oct-05 21:38
Pitchiah4u7-Oct-05 21:38 
Questioncheckbox in datagrid Pin
ahager7-Oct-05 7:07
ahager7-Oct-05 7:07 
QuestionManagment studio Pin
Bueto7-Oct-05 3:52
Bueto7-Oct-05 3:52 
AnswerRe: Managment studio Pin
Bueto9-Oct-05 22:54
Bueto9-Oct-05 22:54 
QuestionSQL Pin
shoaibnawaz6-Oct-05 10:34
shoaibnawaz6-Oct-05 10:34 
AnswerRe: SQL Pin
Colin Angus Mackay6-Oct-05 12:35
Colin Angus Mackay6-Oct-05 12:35 
GeneralRe: SQL Pin
shoaibnawaz7-Oct-05 11:50
shoaibnawaz7-Oct-05 11:50 
GeneralRe: SQL Pin
shoaibnawaz7-Oct-05 12:09
shoaibnawaz7-Oct-05 12:09 
GeneralRe: SQL Pin
Colin Angus Mackay7-Oct-05 13:12
Colin Angus Mackay7-Oct-05 13:12 
QuestionSQL Performance Question Pin
jgallen236-Oct-05 8:29
jgallen236-Oct-05 8:29 
AnswerRe: SQL Performance Question Pin
Colin Angus Mackay6-Oct-05 9:11
Colin Angus Mackay6-Oct-05 9:11 
GeneralRe: SQL Performance Question Pin
jgallen236-Oct-05 9:17
jgallen236-Oct-05 9:17 
QuestionExecuting SQL Script File Pin
KragAapie5-Oct-05 19:32
KragAapie5-Oct-05 19:32 
AnswerRe: Executing SQL Script File Pin
Colin Angus Mackay5-Oct-05 21:59
Colin Angus Mackay5-Oct-05 21:59 
QuestionHow to call stored procedure from update statement Pin
iluha5-Oct-05 15:54
iluha5-Oct-05 15:54 
AnswerRe: How to call stored procedure from update statement (edit) Pin
Nic Rowan6-Oct-05 1:55
Nic Rowan6-Oct-05 1:55 
QuestionImport/Export in MS Access Pin
suzie1005-Oct-05 8:38
suzie1005-Oct-05 8:38 
QuestionHelp with Cursors in Stored Procedures Pin
jszpila5-Oct-05 6:33
jszpila5-Oct-05 6:33 
Hello everyone,
I've just written my first stored procedure and maybe gotten in a little over my head. It's not exactly working out the way I thought; essentially, what I want to do is select a few fields from one table set of rows that meets the SELECT criteria and also where the identifying number is not already in the second table, and then perform a few operations on some of the fields and subsequently insert everything into the second table. I've been told a cursor would assist in this, but I have yet to find a good and clear tutorial/example on T-SQL cursors. Just so you can get a better idea of what I'm talking about, here is my stored procedure thus far:
<br />
CREATE PROCEDURE sp_UpdateLeaders<br />
AS<br />
DECLARE<br />
-- prep all variables<br />
@YspCalc money, <br />
@FeeCalc money, <br />
@Fees money, <br />
@Amount money, <br />
@Ysp money,<br />
@Fee1 money, <br />
@Fee2 money, <br />
@Fee3 money, <br />
@Fee4 money, <br />
@Fee5 money, <br />
@Fee6 money,<br />
@Number varchar(50), <br />
@McName varchar(50), <br />
@Client varchar(50), <br />
@Officer varchar(50),<br />
@FName varchar(25), <br />
@LName varchar(25),<br />
@Date datetime,<br />
@Points integer, <br />
@LoanType integer, <br />
@Mortgage integer<br />
<br />
-- get info from bors<br />
SELECT <br />
TLH_1_68=@FName, TLH_1_69 = @LName, TLH_1_19 = @LoanType, <br />
TLH_1_748 = @Date, TLH_1_2 = @Amount, TLH_2_58 = @McName, <br />
TLH_1_420 = @Mortgage, TLH_1_869 = @Ysp, TLH_1_2 = @Amount,  <br />
GRICA_1_2 = @Fee1, GRICA_1_4 = @Fee2, GRICA_1_6 = @Fee3,  <br />
GRICA_1_10 = @Fee4, GRICA_1_12 = @Fee5, GRICA_1_8 = @Fee6,<br />
TLH_1_317 = @Officer, TLH_1_876 = @Number<br />
FROM MakeDaily53.DBO.bors<br />
WHERE TLH_1_749 Is NULL <br />
AND Filename NOT LIKE '%.2'<br />
-- only for the following branch codes<br />
AND TLH_1_1007 IN ('645','644','642','638','636','599','598','592','589','587','586','582','581','580','579','565','112')<br />
<br />
Print('Before')<br />
<br />
-- check for existing loan in leaderboard<br />
IF NOT EXISTS(SELECT * FROM LeaderBoard WHERE LoanNumber = @Number)<br />
BEGIN<br />
<br />
Print(@Number)<br />
<br />
-- check for nulls<br />
IF @Fee1 = Null<br />
SET @Fee1 = 0<br />
IF @Fee2 = Null<br />
SET @Fee2 = 0<br />
IF @Fee3 = Null<br />
SET @Fee3 = 0<br />
IF @Fee4 = Null<br />
SET @Fee4 = 0<br />
IF @Fee5 = Null<br />
SET @Fee5 = 0<br />
IF @Fee6 = Null<br />
SET @Fee6 = 0<br />
<br />
-- concatenate client name<br />
SET @Client = @FName + ' ' + @LName<br />
-- ysp+rsp caluclation<br />
SET @YspCalc = (((@Ysp - 100)/100)*@Amount)<br />
-- additional fees are calulated differently for 1st and 2nd mortgages<br />
IF (@Mortgage = 1)<br />
SET @FeeCalc = ((@Fee1 + @Fee2 + @Fee3 + @Fee4 + @Fee5 + @Fee6)-1425)<br />
IF (@Mortgage = 2)<br />
SET @FeeCalc = ((@Fee1 + @Fee2 + @Fee3 + @Fee4 + @Fee5 + @Fee6)-275)<br />
<br />
-- insert into leaderboard<br />
INSERT INTO LeaderBoard (ClientName, LoanType, LoanNumber, ClosedDate, LoanAmount, YspSrp, Points, AddFees, McName, MortgageType, LoanOfficer)<br />
VALUES (@Client, @LoanType, @Number, @Date, @Amount, @YspCalc, @Points, @FeeCalc, @McName, @Mortgage, @Officer)<br />
<br />
END<br />
<br />
-- go!<br />
GO


Any help is greatly appreciated. Thanks in advance!

-------------------
abort, retry, fail?
AnswerRe: Help with Cursors in Stored Procedures [long reply] Pin
Colin Angus Mackay5-Oct-05 11:12
Colin Angus Mackay5-Oct-05 11:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.