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

Database

 
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 
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 
Hi,

I tried to apply for update like below in SP.
Error:
Server: Msg 16957, Level 16, State 4, Procedure BicRank, Line 12
FOR UPDATE cannot be specified on a READ ONLY cursor.

SP:

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

/****** Object: Stored Procedure dbo.BicRank Script Date: 08/01/2008 12:44:52 ******/

ALTER 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
for update of mo3_bic,mo3_rank
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
for update of mo3_bic,mo3_rank
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
for update of ytd_bic,ytd_rank
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
for update of ytd_bic,ytd_rank
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
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 
GeneralRe: select count values in sql Pin
Pete O'Hanlon21-Jan-08 4:52
mvePete O'Hanlon21-Jan-08 4:52 
Questionhow to use the keyword LIKE in the SQL query in C# statement Pin
mavii21-Jan-08 2:29
mavii21-Jan-08 2:29 
AnswerRe: how to use the keyword LIKE in the SQL query in C# statement Pin
Pete O'Hanlon21-Jan-08 4:56
mvePete O'Hanlon21-Jan-08 4:56 
AnswerRe: how to use the keyword LIKE in the SQL query in C# statement [modified] Pin
Michael Potter22-Jan-08 5:20
Michael Potter22-Jan-08 5:20 
GeneralUnable to see SQL Server Agent in Object Explorer of sqlserver 2005 Pin
Satish - Developer21-Jan-08 2:24
Satish - Developer21-Jan-08 2:24 

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.