SQL 7 Endless Loop!
Feb 17, 2000
I have an SQL script that runs as part of a batch process in order to number line items in timecards. It basically consists of 2 nested cursors with a number increment and update inside the inner cursor. The problem is that it gets stuck (seemingly at random) in a loop (incrementing and updating within the inner cursor) until I get an arithmetic overflow and it just moves on to the next card. I'm new to my job as a dba and the boss is breathing down my neck.....any assistance would be GREATLY appreciated!!
Thanks..Nick
Here is the code for the script:
declare @SEQ int,
@NUM smallint,
@SUM smallint,
@TSQ int,
@TLI int
declare LINES_OUT_OF_SEQ_CSR cursor for
select TIMECARD_SEQ_NBR
from EMPL_TMCD_VER_DETL
where NEW = '1'
order by TIMECARD_SEQ_NBR
open LINES_OUT_OF_SEQ_CSR
fetch next from LINES_OUT_OF_SEQ_CSR into @SEQ
while @@fetch_status = 0
begin
declare LINES_TO_CHG_SEQ_CSR cursor for
select TIMECARD_SEQ_NBR,
LINE_ITEM_SEQ_NBR
from EMPL_TMCD_VER_DETL
where TIMECARD_SEQ_NBR = @SEQ
order by LINE_ITEM_SEQ_NBR
select @NUM = 0
open LINES_TO_CHG_SEQ_CSR
fetch next from LINES_TO_CHG_SEQ_CSR into @TSQ, @TLI
while @@fetch_status = 0
begin
select @SUM = @NUM +1
select @NUM = @SUM
update EMPL_TMCD_VER_DETL
set TIMECARD_VERSION_ITEM_NBR = @NUM
where LINE_ITEM_SEQ_NBR = @TLI
and TIMECARD_SEQ_NBR = @TSQ
fetch next from LINES_TO_CHG_SEQ_CSR into @TSQ, @TLI
end
deallocate LINES_TO_CHG_SEQ_CSR
fetch next from LINES_OUT_OF_SEQ_CSR into @SEQ
end
deallocate LINES_OUT_OF_SEQ_CSR
go
View 2 Replies
ADVERTISEMENT
May 14, 2004
*** edited by: master4eva ***
Please enclose your code in </ code> tags (without the space between the "</" and "code"). This will make your code easier to read online; therefore, encouraging a response to be faster. It is to your own benefit for your question to be answered in future.
I have already done the editing to include the <code></ code> tags.
*********
I have a trigger that fires this stored procedure during an update event. But i think i am getting an endless loop. Any idea? Thanks in advance....
<code>
ALTER PROCEDURE TrigRetReqRecIDP1
@REID int
AS
Declare @RRID int
Declare @intREID varchar(20)
Declare @intIMID varchar(20)
Declare @RetValint
Declare cr cursor
for
select RRID from RequestRecords where REID=@REID and RRStatus = 'PE'
open cr
fetch next from cr
into
@RRID
while @@fetch_status = 0
Begin
select @intIMID = (select IMID from ImplementationGroup where ImGrpName = 'Help Desk')
insert into ImplementationTasks
(
IMID,
ITStatus,
ITStatusDate
)
VALUES
(
@intIMID,
'2',
GetDate()
)
SET @RetVal = @@IDENTITY
Update RequestRecords
set ITID = @RETVal, RRStatus = 'IA'
where REID = @REID and RRID = @RRID
end
close cr
deallocate cr
GO
View 6 Replies
View Related
Feb 28, 2007
I'm having a problem where I'm using a Execute SQL Task to retrieve a dataset and storing that in an object variable. Then on success of that execute sql task I use a foreach loop task to go through the dataset and do 2 tasks inside the foreach loop. When I execute this package I have ~12 records in the dataset however when I get to the foreach loop in the 2nd iteration it keeps repeating it. It acts like it is stuck on the second record (tuple) and never goes on. I'm using an ForEach ADO Enumerator in the foreach. I've even set a breakpoint on each iteration and no task fails in side the foreach loop. I'm completely perplexed why it will iterate to the 2nd record but get stuck there in an endless loop. I've tried this on 2 different computers (with different data values) and the same thing happens. Does anyone have any suggestions?
View 40 Replies
View Related
Jan 29, 2004
i have created a job that i have scheduled to run every 10 min everything is configured well since i have tested preety everything their is to be tested and found that it was my last step wich as a fetch in it so i imagine that this fetch is making it loop over and over again. the job goes trought all the steps and starts back at the first step and keep going like that till i disable it here is my fetch statement and if you have any clue any help would be widely apreciated.
PS: i suspected it to be that fetch statement causing the havoc ;)
DECLARE
@TransactionNb varchar(10),
@EqId varchar(10)
DECLARE TransactionNb_cursor CURSOR
FOR
SELECT TransactionNb, EqId
FROM DetCom
WHERE UpdCode = 'C'
OPEN TransactionNb_cursor
FETCH NEXT FROM TransactionNb_cursor
INTO @TransactionNb, @EqId
WHILE @@FETCH_STATUS <> -1
BEGIN
-- Vérifier s'il existe une transaction avec le UpdCode = 'C' dans EntCom
IF (SELECT UpdCode
FROM EntCom
WHERE TransactionNb = @TransactionNb and EqId = @EqId) = 'C'
BEGIN
CONTINUE
END
ELSE
BEGIN
RAISERROR (50006, 10, 0, @TransactionNb, @EqId)
END
FETCH NEXT FROM TransactionNb_cursor
INTO @TransactionNb, @EqId
END
CLOSE TransactionNb_cursor
DEALLOCATE TransactionNb_cursor
View 1 Replies
View Related
Aug 16, 2007
I have a table with two columns: OID and Cumulative (witch is the same type as OID)
Each OID can have one or more Cumulatives.
Example of data:
OID Cumulative
167 292
167 294
167 296
168 292
169 302
169 304
The cumulation of each OID don't stop at one cumulation, but can be endless (theoretical).
Example: 167->292->590
So the table would have on more row:
OID Cumulative
295 505
I would like to represent this strucuture in a tree view and I'm looking for a query that could give me a table with this structure:
OID Cumul1 Cumul2 Cuml3 Cuml4 .... Cumuln
in the way I can read the row and have as many child nodes as I have values in the columns. The number of columns depends on the row with most cumulations.
How can I do the query?
Is there a better way as my table with n columns?
Thanks for suggestions
View 1 Replies
View Related
Jul 23, 2005
Hello group!I am having a problem with simplying my query...I would like to get customers' balance info based on how many monthssince they opened their accounts. The tricky part here is accountsstarting with '28' are treated differently than other accounts, theyare given 3 months grace period. In other words, for all otheraccounts, their month0 balance is the balance of their open_month, andmonth1 balance is the balance after the account is opened 1 month, andso on. But accounts starting with '28' month0 balance would be thebalance after the account is opened 3 months, and month1 balance wouldbe the balance after the account is opened 4 months, and so on.My query below works, but since some customers are more than 10 yearsold (more than 120 months), my query is endless! Does anyone know abetter way to do the same job? Many thanks!create table a(person_id int,account int,open_date datetime)insert into a values(1,200001,'11/15/2004')insert into a values(2,280001,'8/20/2004')create table b(account int,balance_date datetime,balance money)insert into b values(200001,'11/30/2004',700)insert into b values(200001,'12/31/2004',800)insert into b values(200001,'1/31/2005',900)insert into b values(200001,'2/28/2005',1000)insert into b values(280001,'8/30/2004',7000)insert into b values(280001,'9/30/2004',8000)insert into b values(280001,'10/31/2004',9000)insert into b values(280001,'11/30/2004',10000)insert into b values(280001,'12/31/2004',15000)insert into b values(280001,'1/31/2005',20000)insert into b values(280001,'2/28/2005',30000)--Ideal output--person_idacc_nomonth0_balancemonth1_balancemonth2_balancemonth3_balance1200000170080090010002280000110000150002000030000select a.person_id,a.account,month0_balance=casewhen a.account like '2%' and a.account not like '28%'thensum(case datediff(mm, a.open_date, balance_date) when 0then b.balance else 0 end)else sum(case datediff(mm, a.open_date, balance_date)when 3 then b.balance else 0 end)end,month1_balance =casewhen a.account like '2%' and a.account not like '28%'thensum(case datediff(mm, a.open_date, balance_date) when 1then b.balance else 0 end)else sum(case datediff(mm, a.open_date, balance_date)when 4 then b.balance else 0 end)endfrom a as ajoin b as bon a.account=b.accountgroup by a.person_id, a.account
View 3 Replies
View Related
Jan 15, 2007
I have a package which runs fine, when I execute it with my account (e.g. double-click on the .dtsx file and run it).
Now I would like to establish a job, which starts the package. I created first a credential for my Account (which is a domain administrator account also for the box, where SQL Server is running on), then I defined a proxy to this credential.
In the job definition I changed the Run as... to this Proxy (it is a SSIS Proxy) and then I started the job.
Th job does NOT abend, it runs forever! So I have to stop it manually.
In the log I can see as last entry : "operation complete". It stops at a "Execute process task" where I call the bcp utility.
Does anyone has an idea, why a package can run forever?!?!
Regards
Norbert
View 1 Replies
View Related
Apr 11, 2015
I created a function to use in a View, works similar to DATEADD but only with my company's Business days Monday-Thursday.
I am running a query but it never ends to run.
This is the function:
USE [RA_dev]
GO
/****** Object: UserDefinedFunction [Production].[GBDATEADD] Script Date: 4/11/2015 5:58:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
[Code] ...
This is how I am trying to use it in the View:
Production.GBDATEADD(Production.Schedule.START_DATE, Production.Operations_Data_Pool.MFG_DAY - 1) AS SCH_DATE
View 2 Replies
View Related
May 28, 2010
difference between FOR LOOP and FOREACH LOOP with example(if possible) in SSIS.
View 4 Replies
View Related
Feb 22, 2006
I have a table with RowID(identity). I need to loop though the table using RowID(not using a cursor). Please help me.
Thanks
View 6 Replies
View Related
Mar 3, 2006
I have a foreach loop that is supposed to loop through a recordset, however it doesn't loop. It just repeats the same row, row after row.
I would like to look into the recordset variable but I can't because it is a COM object and the ADODB namespace is not available in the script task.
Any solution to this? anyone experienced anything similar
View 1 Replies
View Related
Jul 8, 2006
I have a table called Tbltimes in an access database that consists of the following fields:
empnum, empname, Tin, Tout, Thrs
what I would like to do is populate a grid view the a select statement that does the following.
display each empname and empnum in a gridview returning only unique values. this part is easy enough. in addition to these values i would also like to count up all the Thrs for each empname and display that sum in the gridview as well. Below is a little better picture of what I€™m trying to accomplish.
Tbltimes
|empnum | empname | Tin | Tout | Thrs |
| 1 | john | 2:00PM | 3:00PM |1hr |
| 1 | john | 2:00PM | 3:00PM | 1hr |
| 2 | joe | 1:00PM | 6:00PM | 5hr |
GridView1
| 1 | John | 2hrs |
| 2 | Joe | 5hrs |
im using VWD 2005 for this project and im at a loss as to how to accomplish these results. if someone could just point me in the right direction i could find some material and do the reading.
View 18 Replies
View Related
Feb 23, 2006
I have source and destination table names in the database(one table) and I need to read the source and destination tables one by one...
My Lookp table is like the following...
Srn srctable desttable
1 SRC1 DEST1
2 SRC2 DEST2
3 SRC3 DEST3
Now I want one package to load from source to destination.. how do I do it.. I dont know how to use....
How do I run the pacakge for each of the rows... ..............................
View 1 Replies
View Related
Aug 20, 2007
I used to loop through recordsets with ease in old classic .asp pages.
Please Help me understand how Professionals now loop through and update tables using JUST SQL Query Analyzer using my pseudo-code provided below.
I would love to learn how to do it to better develop my skills.
SELECT * FROM zz_2007_Booth_Visitors
WHERE COALESCE ([Product Interest - Other Actuator],
[Product Interest - Chillers],
[Product Interest - Other Chiller],
[Product Interest - Electronic Products],
[Product Interest - Other network interfaces],
[Product Interest - Fittings],
[Product Interest - High Vacuum],
[Product Interest - Other high vacuum actuators],
[Product Interest - Pick& Place and Transfer],
[Product Interest - Teflon Products],
[Product Interest - Training],
[Product Interest - Valves& Manifolds],
[Product Interest - Actuators]) Is Not Null
Order BY [Contact Name]
IF [Product Interest - Actuators] IS NOT NULL THEN
UPDATE Booth_Visitors_Data Set Act_Phuematic = 1 Where [Contact Name] = [Contact Name]
IF [Product Interest - Other Actuator] IS NOT NULL THEN
UPDATE Booth_Visitors_Data Set Act_Electric = 1 Where [Contact Name] = [Contact Name]
IF [Product Interest - Other Chillers] IS NOT NULL THEN
UPDATE Booth_Visitors_Data Set Chiller = 1 Where [Contact Name] = [Contact Name]
View 24 Replies
View Related
Jan 12, 2008
Dear All.
Have a nice day.
I have db table, I need to update all fields of table.
Please can you write code," for loop " how can update all fields of my table by loop.
Thanks.
Zahyea.
View 3 Replies
View Related
Mar 3, 2008
Hello everyone,I've got this While loop here which is giving me a problem:WHILE (SELECT ProductId FROM _ShoppingCart WHERE CartId = @CartId) IS NOT NULLBEGIN DECLARE @ProdId int, @ProdSize varchar, @ProdQuan int SELECT @ProdId = ProductId, @ProdSize = ProductSize, @ProdQuan = Quantity FROM _ShoppingCart WHERE CartId = @CartId If @ProdSize = 'XL' BEGIN UPDATE _ProductBatches SET XL = '0' WHERE ProductId = @ProdId END DELETE FROM _ShoppingCart WHERE ProductId = @ProdId AND CartId = @CartIdEND The problem is that the IF statement isn't being executed. And I know for a fact that 'XL' is ProductSize in my _ShoppingCart database. Whats even stranger is that my delete statement is being executed. So @ProdId is Being set correctly, but when it gets to the IF @ProdSize = 'XL' it doesn't get executed for some reason. If @ProdId is being recognized correctly in my DELETE statement, why is my @ProdSize not being reconized correctly in my IF statement. I checked my _ShoppingCart database, and my ProductSize is definitely 'XL'. Can any one see what could be going on here. Thank you, Alec
View 7 Replies
View Related
Mar 4, 2008
Hello everyone...... I'm trying to do the following but am having issues:WHILE (SELECT ProductId FROM _ShoppingCart WHERE CartId = @CartId) IS NOT NULLBEGIN execute code with item......... erase itemEND In the while loop I want to execute code from each item in my _ShoppingCart and then erase them until there are no more items. However the above code gives me the error: "Subquery returned more than 1 value. This is not permitted........" It works fine when there is only one item. Does any one know what format to use when dealing with more that one entry? Thank you, Alec
View 2 Replies
View Related
Sep 21, 2000
hi,
I am trying to find a way of using a loop that won't be an endless loop because I have to insert parts of a string until the string reaches the end. I am unable to make the loop get to a point where the statement is false.
Is there anyway I can find out the length of the string so that I can tell the statement to loop while the statement is true?
Help!!!!!!!!!!!!1
View 1 Replies
View Related
Jan 26, 2004
HeaderLoop: for forHeader as curHeader dynamic scroll cursor for
select lngALSHeadrID from "DBA".ALSHEADR where lngFedTaxID>0 do
set AcctNum=lngALSHeadrID;
exec "DBA".sp_ALSHeadr2Policy(AcctNum);
set Cntr=Cntr+1
end for;
The above is the sybase version of a 'for loop' . The query
select lngALSHeadrID from "DBA".ALSHEADR where lngFedTaxID>0 results in 1000 results.
How do I change that in SQL?? Do we have a for loop ??
I checked in BOL but it is confusing with "browse" etc n some other options.
can I write like this?
for { Browse { declare curHeader dynamic cursor for
select lngALSHeadrID from "DBA".ALSHEADR where lngFedTaxID>0 }
set @AcctNum=lngALSHeadrID;
exec "DBA".sp_ALSHeadr2Policy(@AcctNum);
set @Cntr=@Cntr+1
}
I duno its just my guess, can any one help me out. @Cntr and @Acctnum are declared
in the beginnning.
tks
View 14 Replies
View Related
Apr 11, 2008
I get the following results on a view.
Job | Qty | Desc
06-182 | 1 | B1011
06-324 | 2 | A1102
99-999 | 4 | AB839
What I would like is the following.
Job | Qty | Desc
06-182 | 1 | B1011
06-324 | 1 | A1102
06-324 | 1 | A1102
99-999 | 1 | AB839
99-999 | 1 | AB839
99-999 | 1 | AB839
99-999 | 1 | AB839
View 2 Replies
View Related
Apr 18, 2008
I have a loop is running with no end point. What I'm trying to do is get the Grand total of each row where BudgetNodeID = 120. Your help is much appreciated.
AV
Set NoCount on
Declare @Amt as bigint
Declare @Cont as bigint
Declare @Mark as Bigint
Declare @Total as bigint
Declare @BudgetNodeID as Bigint
Declare @GTotal as bigint
Set @BudgetNodeID ='120'
Set @Amt = 0
set @Cont = 0
set @Mark = 0
set @GTotal = 0
While exists (Select * from xBudgetNodeCosts where BudgetNodeID =@BudgetNodeID) Begin
select @Amt = IsNull(xBudgetNodeCosts.Qty,0) * IsNull(xBudgetNodeCosts.CostRate,0)
FROM xBudgetNode INNER JOIN
xBudget ON xBudgetNode.BudgetID = xBudget.BudgetID INNER JOIN
xBudgetNodeCosts ON xBudgetNode.BudgetNodeID = xBudgetNodeCosts.BudgetNodeID left JOIN
xProposalChanges pc on xbudgetnodecosts.ProposalChangeID = pc.ProposalChangeID
WHERE (xBudgetNodeCosts.BudgetNodeID = @BudgetNodeID) AND (xBudget.IsActive = '1') AND (xbudgetnodecosts.ProposalChangeID IS NULL OR
pc.Status='Approved')
select @Cont = @Amt * (xBudgetNodeCosts.Contingency/100)
FROM xBudgetNode INNER JOIN
xBudget ON xBudgetNode.BudgetID = xBudget.BudgetID INNER JOIN
xBudgetNodeCosts ON xBudgetNode.BudgetNodeID = xBudgetNodeCosts.BudgetNodeID left JOIN
xProposalChanges pc on xbudgetnodecosts.ProposalChangeID = pc.ProposalChangeID
WHERE (xBudgetNodeCosts.BudgetNodeID = @BudgetNodeID ) AND (xBudget.IsActive = '1') AND (xbudgetnodecosts.ProposalChangeID IS NULL OR
pc.Status='Approved')
select @Mark = @Cont * (xBudgetNodeCosts.Markup/100)
FROM xBudgetNode INNER JOIN
xBudget ON xBudgetNode.BudgetID = xBudget.BudgetID INNER JOIN
xBudgetNodeCosts ON xBudgetNode.BudgetNodeID = xBudgetNodeCosts.BudgetNodeID left JOIN
xProposalChanges pc on xbudgetnodecosts.ProposalChangeID = pc.ProposalChangeID
WHERE (xBudgetNodeCosts.BudgetNodeID = @BudgetNodeID) AND (xBudget.IsActive = '1') AND (xbudgetnodecosts.ProposalChangeID IS NULL OR
pc.Status='Approved')
-- compute the sell
select @Total = @Amt + @Cont + @Mark
-- add to grand total
Select @GTotal = Sum(@Total+ @GTotal)
select @GTOtal
end
View 5 Replies
View Related
Jun 17, 2008
Hi
I want to loop this command with a pause. It must run every 30 min to refresh my query. Can anyone assist me.
select * from BULKPICKXLOC
Thanks
View 4 Replies
View Related
Apr 11, 2006
Exist a funtion that I can use in a SP that do something like the for to next or Do while Loop do?
View 5 Replies
View Related
Jan 30, 2007
I need to keep the first 4 values above 80 or the first 2 values above 90. If there are not enough, I need to keep as many values as possible. Should this be done with a while loop, if so, how would it be done.
View 19 Replies
View Related
Mar 13, 2007
hello,
i have this SP to tally up my inventory tables.. im finding a way to loop through my table tblitemdetail to get necessary parameter to be insert into my other SP (SP_StkAdj_tbl_alignmt) that should accept this params (from the itemdetail) :-
@ItemID ='',
@ClientID='',
@CustomLotNo ='',
@UDF1=NULL,
@UDF2=NULL,
@UDF3 =NULL,
@UDF4 =NULL,
@UDF5=NULL,
@UDF6 =NULL,
@UDF7 =NULL,
@UDF8 =NULL,
@UDF9 =NULL,
@UDF10 =NULL,
@StockID ='0950-4388',
@RecvOwn ='OWN',
@ConsignorID ='JAB1MY'
EG:i will GROUP BY my itemdetail so it will give me the x records of data with :-
SELECT ItemID, CustomLotNo, Ownership, ConsignorID, RecvUDF1, RecvUDF2, RecvUDF3, ownerstatus
FROM tblItemDetail
GROUP BY ItemID, CustomLotNo, Ownership, ConsignorID, RecvUDF1, RecvUDF2, RecvUDF3,ownerstatus
ORDER BY ItemID
with the result then, i need to insert the param into the SP:SP_StkAdj_tbl_alignmt so that it perform the calculation.
so i guess this will need some looping from the result set i get from the group by and some Sp calling from main Sp
~~~Focus on problem, not solution~~~
View 20 Replies
View Related
Apr 18, 2007
hi all, ive no idea what's wrong with my while loop nested in IF .. it only work correctly when i remove the while from IF :-
IF @Picktype='FI'
BEGIN
-- Insert data into @Stage to play around
DECLARE@Stage TABLE (RecID INT IDENTITY(1, 1), ItemStorageID VARCHAR(12), Qty MONEY, RecvDate DATETIME,BB char(1))
WHILE (SELECT COALESCE(SUM(Qty), 0) FROM @Stage) < @WantedValue AND @@ROWCOUNT > 0
INSERT@Stage (ItemStorageID, Qty, RecvDate, BB)
SELECT TOP 1t1.ItemStorageID,
t1.Qty,
t1.RecvDate,
t1.BB
FROM#DataList AS t1
LEFT JOIN@Stage AS s ON s.ItemStorageID = t1.ItemStorageID
WHEREs.ItemStorageID IS NULL
ORDER BYt1.RecvDate,
t1.Qty DESC
IF (SELECT COALESCE(SUM(Qty), 0) FROM @Stage) >= @WantedValue
SELECTrecID,
ItemStorageID,
Qty,
RecvDate,
BB
FROM@Stage
ELSE
select * from #DataList
END
correct result after i remove the while from inside IF
DECLARE@Stage TABLE (RecID INT IDENTITY(1, 1), ItemStorageID VARCHAR(12), Qty MONEY, RecvDate DATETIME,BB char(1))
WHILE (SELECT COALESCE(SUM(Qty), 0) FROM @Stage) < @WantedValue AND @@ROWCOUNT > 0
INSERT@Stage (ItemStorageID, Qty, RecvDate, BB)
SELECT TOP 1t1.ItemStorageID,
t1.Qty,
t1.RecvDate,
t1.BB
FROM#DataList AS t1
LEFT JOIN@Stage AS s ON s.ItemStorageID = t1.ItemStorageID
WHEREs.ItemStorageID IS NULL
ORDER BYt1.RecvDate,
t1.Qty DESC
IF @pickType='FI'
BEGIn
IF (SELECT COALESCE(SUM(Qty), 0) FROM @Stage) >= @WantedValue
SELECTrecID,
ItemStorageID,
Qty,
RecvDate,
BB
FROM@Stage
end
~~~Focus on problem, not solution~~~
View 9 Replies
View Related
Sep 18, 2007
I have the following stored procedure which enters items bought by the usr in the database, inserting the user's ID, the item and the price. now every user has a unique id and every user can only buy three items; thus only three inputs must be inserted in the table, how can i do that? This is the current SP i have...
ALTER PROCEDURE [dbo].[spA_ALW_InsertIntoMLAGoods]
@MLAFormIDFINT,
@DescriptionNVARCHAR(50),
@AmountINT
AS
BEGIN
BEGIN TRY
--UPDATE MLAGoods
--SET
--MLAFormIDF=@MLAFormIDF,
--Description=@Description,
--Amount=@Amount
--WHERE MLAFormIDF = @MLAFormIDF
INSERT INTO MLAGoods
(
MLAFormIDF,
Description,
Amount
)
VALUES
(
@MLAFormIDF,
@Description,
@Amount
)
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS [ERRORMSG], ERROR_SEVERITY() AS [ERRORSEV]
RETURN @@ERROR
END CATCH
END
View 4 Replies
View Related
Sep 25, 2007
Hi i have a sql loop query which i have working in asp fine, i have altered it to try and get it working as a stored procedure.
but i am not sure what the syntax is.
can someone help please.
many thanks
DECLARE
CURSOR GetWebOrder_cur IS
SELECT O_R_ID, O_Name, O_Add_1, O_DB_Code, O_Add_2, O_Add_3, O_Add_4, O_Add_5, O_Add_6, O_PostCode, O_CCode, O_Service, O_Instore, O_STC_Code, O_ID
FROM [newserver].dbo.X_TBL_ORDER
WHERE NewOrder = 0
BEGIN
FOR GetWebOrder_rec IN GetWebOrder_cur LOOP
-- SET ALL FIELDS
set R_ID34 = GetWebOrder_cur("O_R_ID")
set R_Name = GetWebOrder_cur("O_Name")
set R_Contact = GetWebOrder_cur("O_Add_1")
set R_Code = GetWebOrder_cur("O_DB_Code")
set R_Add_1 = GetWebOrder_cur("O_Add_2")
set R_Add_2 = GetWebOrder_cur("O_Add_3")
set R_Add_3 = GetWebOrder_cur("O_Add_4")
set R_Add_4 = GetWebOrder_cur("O_Add_5")
set R_Add_5 = GetWebOrder_cur("O_Add_6")
set R_Add_6 = GetWebOrder_cur("O_Add_6")
set R_PostCode = GetWebOrder_cur("O_PostCode")
set R_CostCode = GetWebOrder_cur("O_CCode")
set R_Delivery = GetWebOrder_cur("O_Service")
set R_Instore = GetWebOrder_cur("O_Instore")
set R_STCODES = GetWebOrder_cur("O_STC_Code")
set WebOrderID = GetWebOrder_cur("O_ID")
-- GET MAX ID
SELECT Max(O_ID) AS MAXOID FROM dbo.X_TBL_ORDER
-- INSERT ORDER INTO F4 ORDERS
INSERT INTO dbo.X_TBL_ORDER
(O_Date, O_R_ID, O_Name, O_DB_Code, O_Add_1, O_Add_2, O_Add_3, O_Add_4, O_Add_5, O_Add_6, O_PostCode, O_CCode, O_Service, O_O_By, O_Instore, O_STC_Code)
VALUES
(getdate(), R_ID34, R_Name, R_Code, R_Contact, R_Add_1, R_Add_2, R_Add_3, R_Add_4, R_Add_5, R_PostCode, R_CostCode, R_Delivery, R_Contact, R_Instore, R_STCODES)
-- UPDATE VIRTUAL SERVER SET NewOrder = 1
UPDATE [newserver].dbo.X_TBL_ORDER
SET NewOrder = 1
WHERE O_ID = WebOrderID
-- SET CURSOR FOR ORDERLINES
CURSOR orderlines_cur IS
SELECT *
FROM [newserver].dbo.X_TBL_ORDER_LINE
WHERE OL_O_ID = @WebOrderID
-- OPEN LOOP THROUGH ORDERLINES
FOR orderlines_rec in orderlines_cur LOOP
-- SET ORDERLINE FIELDS
set B_St_Code = orderlines_cur("OL_St_Code")
set B_Description = orderlines_cur("OL_Desc")
set B_Qty = orderlines_cur("OL_Qty")
set B_dbcode = orderlines_cur("OL_DB_Code")
-- INSERT INTO F4 ORDERLINES
INSERT INTO dbo.X_TBL_ORDER_LINE
(OL_O_ID, OL_St_Code, OL_Desc, OL_Qty, OL_Allocated, OL_Despatch, OL_DB_Code)
VALUES
(B_preorderID, B_St_Code, B_Description, B_Qty, B_Qty, B_Qty, B_dbcode)
-- CLOSE LOOP THROUGH ORDERLINES
END LOOP;
END LOOP;
END;
View 9 Replies
View Related
Nov 21, 2007
Hi,
I have this scenario: I have a table one database in sql called facttable_Temp with columns CustomerName, ItemKey.The fields are varchar.
I have another table called Accounts in a different database. Accounts contains fields such as CustomerName,Account. The fields are varchar.
What I need to do is to check if the values for CustomerName from table FactTable_Temp exists in the field CustomerName in the table Accounts.
If it exists then I need to insert the entire row for that CustomerName including ItemKey into a 3rd table called FactTable.
What is the best way of accomplishing this in SSIS?
Thanks
Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.
View 1 Replies
View Related
Feb 14, 2008
hi i need to do a loop inside a stored procedure, just not sure how to go about it!
this is what i need
select count(TI_ID) AS REC_COUNT
FROM TRANSIT...T_TBL_TRANSIT
WHERE DATEDIFF(m, TI_Date, getdate())>12
CASE WHEN REC_COUNT > 1 THEN
===LOOP THROUGH AND DELETE 1000 AT A TIME===
DELETE top 1000 FROM TRANSIT...T_TBL_TRANSIT
WHERE DATEDIFF(m, TI_Date, getdate())>12
END CASE
View 7 Replies
View Related
Jul 23, 2005
What I am trying to do is to get balances at each month-end from Jan toDec 2004. Now I am doing it by manually changing the date for eachmonth, but I want to do all the months at one time. Is there a way toadd something like a do loop to achieve that goal? Please see my querybelow. Thanks so much!declare @month_date_b smalldatetime--B month beginning datedeclare @month_date_e smalldatetime--E month ending dateselect @month_date_b='9/1/2004'select @month_date_e='9/30/2004'select a.person_id, a.fn_accno, a.fn_bal, b.mm_openfrom fn_mm_fnbal as ajoin fn_mm_list as bon a.person_id=b.person_idand b.mm_open < @month_date_ewhere a.bal_date between @month_date_b and @month_date_egroup by a.person_id, a.fn_accno, a.fn_bal, b.mm_openorder by a.fn_accno, a.fn_bal
View 2 Replies
View Related
Aug 17, 2005
helloDoes exist in SQL language "for" loop ? If yes, what syntax does it has ?best wishesAdam
View 9 Replies
View Related
May 9, 2007
Hello,
Please, could someone explain me how "For Loop" funtions?
because I need to load data depending on a variable?
Can I use For loop to do that?
thanks
View 1 Replies
View Related