Click here to Skip to main content
15,891,136 members
Home / Discussions / Database
   

Database

 
GeneralUpdate with Addition Pin
Expert Coming23-Jan-08 14:47
Expert Coming23-Jan-08 14:47 
GeneralRe: Update with Addition Pin
pmarfleet23-Jan-08 19:46
pmarfleet23-Jan-08 19:46 
GeneralRe: Update with Addition Pin
Paddy Boyd24-Jan-08 2:21
Paddy Boyd24-Jan-08 2:21 
QuestionIs there a way to optimize this query and get the same results? Pin
Skanless23-Jan-08 11:21
Skanless23-Jan-08 11:21 
AnswerRe: Is there a way to optimize this query and get the same results? Pin
PIEBALDconsult23-Jan-08 14:30
mvePIEBALDconsult23-Jan-08 14:30 
GeneralBuilding up a query string Pin
ssTahoe23-Jan-08 7:48
ssTahoe23-Jan-08 7:48 
GeneralCreating a CLR User Defined Type for Time only Pin
AAGTHosting23-Jan-08 7:25
AAGTHosting23-Jan-08 7:25 
GeneralHelp in Stored Procedure sqlserver Pin
aaraaayen22-Jan-08 20:55
aaraaayen22-Jan-08 20:55 
Hi all,

I am executing the following SP. But when i execute it, I get the error

Server: Msg 16929, Level 16, State 1, Procedure BicRank, Line 34.
The cursor is readonly. The Statement has been terminated.

Please help me to come out from this problem. Its very urgent for me.

This is the SP.


SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

/****** Object: Stored Procedure dbo.BicRank /


CREATE PROCEDURE BicRank
AS
-- determine mo3 bic and m03 ranking for mtc dmoq's ('TTR_1', 'TTR_2', 'TTR_3', 'PROGRS')
-- ADDED ('TTR_6', 'TTR_12', 'TTR_24') By Nirmala 02/09/2007
--rankings are completed per dmoq, service, bicuniverse combination
--100% is considered best

Declare BicRank_DESC Cursor
for Select dmoq + service + bicuniverse as compare, mo3_percent from mtce_toexcel
where (Mo3_Percent < 101) and dmoq in ('TTR_1','TTR_2','TTR_3','TTR_6','TTR_12','TTR_24','PROGRS')
order by compare, Mo3_percent desc
declare @3mo as float, @rank as int, @heldcompare as varchar(60), @bic as float, @firstbic as float, @compare as varchar(60)
declare @dmoq as varchar(20), @service as varchar(20), @bicuniverse as varchar(6), @RCD_CNT INTEGER
OPEN BicRank_DESC
set @heldcompare = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
FETCH NEXT FROM bicrank_DESC into @compare, @3mo
while (@@fetch_status <> -1)
begin
IF (@heldcompare <> @compare)
begin
set @rank = 1 set @bic = @3mo set @firstbic = @3mo set @heldcompare = @compare
end
ELSE IF (@3mo <> @bic)
begin
set @rank = @rank + 1 set @bic = @3mo
end

SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRANSACTION


Update MTce_toExcel set Mo3_bic = @firstbic, Mo3_rank = @rank where current of BicRank_DESC
FETCH NEXT FROM bicrank_DESC into @compare, @3mo
END

commit transaction

CLOSE BicRank_DESC
DEALLOCATE BicRank_DESC
--determine mo3 bic and m03 ranking for mtc dmoq's ('FAIL_FREQ', 'NRF', 'MTTR','MTTR_3')
--rankings are completed per dmoq, service, bicuniverse combination
--0% is considered best
Declare BicRank_ASC Cursor
for Select dmoq + service + bicuniverse as compare, mo3_percent from mtce_toexcel
where ( Mo3_Percent < 101 AND MO3_PERCENT IS NOT NULL) and dmoq in ('FAIL_FREQ', 'NRF', 'MTTR','MTTR_3','MTTR_F')
order by compare, Mo3_percent asc
OPEN BicRank_ASC
set @heldcompare = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
FETCH NEXT FROM bicrank_ASC into @compare, @3mo
while (@@fetch_status <> -1)
begin
IF @heldcompare <> @compare
begin
set @rank = 1 set @bic = @3mo set @firstbic = @3mo set @heldcompare = @compare
end
ELSE IF (@3mo <> @bic)
begin
set @rank = @rank + 1 set @bic = @3mo
end

Update MTce_toExcel set Mo3_bic = @firstbic, Mo3_rank = @rank where current of BicRank_ASC
FETCH NEXT FROM bicrank_ASC into @compare, @3mo
END
CLOSE BicRank_ASC
DEALLOCATE BicRank_ASC
--determineYTD bic andYTD ranking for mtc dmoq's ('FAIL_FREQ', 'NRF', 'MTTR','MTTR_3')
--rankings are completed per dmoq, service, bicuniverse combination
--0% is considered best
Declare BicRank_YTD_DESC Cursor
for Select dmoq + service + bicuniverse as compare, YTD_percent from mtce_toexcel
where ( YTD_Percent < 101 AND YTD_PERCENT IS NOT NULL) and dmoq in ('FAIL_FREQ', 'NRF', 'MTTR','MTTR_3','MTTR_F')
order by compare, YTD_percent asc
declare @YTD float
OPEN BicRank_YTD_DESC
set @heldcompare = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
FETCH NEXT FROM bicrank_YTD_DESC into @compare, @YTD
while (@@fetch_status <> -1)
begin
IF @heldcompare <> @compare
begin
set @rank = 1 set @bic = @YTD set @firstbic = @YTD set @heldcompare = @compare
end
ELSE IF (@YTD <> @bic)
begin
set @rank = @rank + 1 set @bic = @YTD
end

Update MTce_toExcel set YTD_bic = @firstbic,YTD_rank = @rank where current of BicRank_YTD_DESC
FETCH NEXT FROM bicrank_YTD_DESC into @compare, @YTD
END
CLOSE BicRank_YTD_DESC
DEALLOCATE BicRank_YTD_DESC
--determineYTD bic andYTD ranking for mtc dmoq's ('TTR_1', 'TTR_2', 'TTR_3', 'PROGRS')
--rankings are completed per dmoq, service, bicuniverse combination
--100% is considered best
-- ADDED ('TTR_6', 'TTR_12', 'TTR_24') By Nirmala 02/09/2007

Declare BicRank_YTD_ASC Cursor
for Select dmoq + service + bicuniverse as compare, YTD_percent from mtce_toexcel
where (YTD_Percent < 101 ) and dmoq in ('TTR_1', 'TTR_2', 'TTR_3','TTR_6','TTR_12','TTR_24','PROGRS')
order by compare, YTD_percent desc
OPEN BicRank_YTD_ASC
set @heldcompare = 'xxxxxxxxxxxxxxxxxxxxxxx'
FETCH NEXT FROM bicrank_YTD_ASC into @compare, @YTD
while (@@fetch_status <> -1)
begin
IF @heldcompare <> @compare
begin
set @rank = 1 set @bic = @YTD set @firstbic = @YTD set @heldcompare = @compare
end
ELSE IF (@YTD <> @bic)
begin
set @rank = @rank + 1 set @bic = @YTD
end

Update MTce_toExcel set YTD_bic = @firstbic,YTD_rank = @rank where current of BicRank_YTD_ASC
FETCH NEXT FROM bicrank_YTD_ASC into @compare, @YTD
END
CLOSE BicRank_YTD_ASC
DEALLOCATE BicRank_YTD_ASC
--
--Populate MO3_BIC on records where MO3_BIC is null
--This is due to the MO3_PERCENT being 101, 102 or NULL
--
Declare BicRank_null Cursor
for Select distinct dmoq, service, bicuniverse from mtce_toexcel where mo3_bic is null
OPEN BicRank_null
FETCH NEXT FROM bicrank_null into @dmoq, @service, @bicuniverse
while (@@fetch_status <> -1)
begin
Declare
mo3_bic Cursor For
Select DISTINCT MO3_BIC from mtce_toexcel where mo3_bic is NOT null and
dmoq = @dmoq And service = @service and bicuniverse = @bicuniverse
SET @RCD_CNT = @@ROWCOUNT
-- get the mo3_bic
Open mo3_bic
Fetch Next From mo3_bic Into @FIRSTBIC
if @RCD_CNT > 0
BEGIN
UPdate MTce_toExcel set Mo3_bic = @firstbic where mo3_bic is null and
dmoq = @dmoq And service = @service and bicuniverse = @bicuniverse
END
Close mo3_bic
Deallocate mo3_bic
FETCH NEXT FROM bicrank_null into @dmoq, @service, @bicuniverse
END
CLOSE BicRank_null
DEALLOCATE BicRank_null
--
--Populate YTD_BIC on records where YTD_BIC is null
--This is due to the YTD_PERCENT being 101, 102 or NULL
--
Declare BicRank_null_ytd Cursor
for Select distinct dmoq, service, bicuniverse from mtce_toexcel where YTD_bic is null
OPEN BicRank_null_ytd
FETCH NEXT FROM bicrank_null_ytd into @dmoq, @service, @bicuniverse
while (@@fetch_status <> -1)
begin
Declare
YTD_bic Cursor For
Select distinct ytd_bic from mtce_toexcel where YTD_bic is not null and
dmoq = @dmoq And service = @service and bicuniverse = @bicuniverse
SET @RCD_CNT = @@ROWCOUNT
-- get theYTD_bic
Open YTD_bic
Fetch Next From YTD_bic Into @firstbic
if @RCD_CNT > 0
BEGIN
Update MTce_toExcel set YTD_bic = @firstbic where YTD_bic is null and
dmoq = @dmoq And service = @service and bicuniverse = @bicuniverse
END
Close YTD_bic
Deallocate YTD_bic
FETCH NEXT FROM bicrank_null_ytd into @dmoq, @service, @bicuniverse
END
CLOSE BicRank_null_ytd
DEALLOCATE BicRank_null_ytd



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


Thanks and Regards,
GeneralRe: Help in Stored Procedure sqlserver Pin
pmarfleet22-Jan-08 22:07
pmarfleet22-Jan-08 22:07 
GeneralRe: Help in Stored Procedure sqlserver Pin
KANGAROO_22-Jan-08 22:25
KANGAROO_22-Jan-08 22:25 
GeneralRe: Help in Stored Procedure sqlserver Pin
andyharman22-Jan-08 22:34
professionalandyharman22-Jan-08 22:34 
GeneralRe: Help in Stored Procedure sqlserver Pin
aaraaayen22-Jan-08 23:31
aaraaayen22-Jan-08 23:31 
GeneralRe: Help in Stored Procedure sqlserver Pin
aaraaayen23-Jan-08 0:02
aaraaayen23-Jan-08 0:02 
GeneralAttaching an .MDF file without an LDF file Pin
ffowler22-Jan-08 11:25
ffowler22-Jan-08 11:25 
GeneralRe: Attaching an .MDF file without an LDF file Pin
Mike Dimmick23-Jan-08 12:40
Mike Dimmick23-Jan-08 12:40 
QuestionSybase Linked Server Pin
mobius11100122-Jan-08 3:22
mobius11100122-Jan-08 3:22 
QuestionHow to use one sp's result in my new Sp Pin
pashitech21-Jan-08 18:26
pashitech21-Jan-08 18:26 
AnswerRe: How to use one sp's result in my new Sp Pin
Joe21-Jan-08 18:49
Joe21-Jan-08 18:49 
AnswerRe: How to use one sp's result in my new Sp Pin
andyharman22-Jan-08 0:13
professionalandyharman22-Jan-08 0:13 
GeneralCreating a User Defined Type For Time Pin
AAGTHosting21-Jan-08 13:46
AAGTHosting21-Jan-08 13:46 
GeneralRe: Creating a User Defined Type For Time Pin
PIEBALDconsult21-Jan-08 14:54
mvePIEBALDconsult21-Jan-08 14:54 
GeneralRe: Creating a User Defined Type For Time Pin
AAGTHosting21-Jan-08 20:35
AAGTHosting21-Jan-08 20:35 
GeneralAccess/Jet SQL (Uggh!!) Code Commenting Pin
martin_hughes21-Jan-08 10:52
martin_hughes21-Jan-08 10:52 
GeneralMysql strong typed dataset relations error. Pin
Y_R21-Jan-08 4:28
Y_R21-Jan-08 4:28 
Generalselect count values in sql Pin
eyeseetee21-Jan-08 4:01
eyeseetee21-Jan-08 4:01 

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.