E, došlo je do novog razvoja situacije... Kada iz upita kojim punim kursor uklonim jedan od kriterija za sortiranje, radi ko zmaj:
Code:
DECLARE myCursor CURSOR
FOR
SELECT customerId, readingId, price, categoryDiscount, readValue, flatDiscount, consumption
FROM dbo.ViewBillingDataPreliminary
ORDER BY /*customerId,*/ readingId
Inače View:
Code:
SELECT dbo.Reading.readingId, dbo.Reading.readValue, dbo.Reading.readingDate, dbo.Reading.readingForMonth, dbo.Reading.flow,
dbo.Meter.meterId, dbo.Contract.numberOfMembers, dbo.Customer.customerId, dbo.Customer.name, dbo.Customer.surname,
dbo.Customer.balance, dbo.Services.serviceId, dbo.Services.serviceName, dbo.SevicesPricelist.priceUnit, dbo.SevicesPricelist.price,
dbo.CustomerType.customerTypeId, dbo.CustomerType.type, dbo.CustomerCategory.customerCategoryId, dbo.CustomerCategory.Category,
dbo.CustomerCategory.categoryDiscount, dbo.CustomerCategory.flatDiscount, dbo.Reading.consumption, dbo.Reading.cost
FROM dbo.Reading INNER JOIN
dbo.Meter ON dbo.Reading.meterId = dbo.Meter.meterId INNER JOIN
dbo.Contract_Meter ON dbo.Meter.meterId = dbo.Contract_Meter.meterId INNER JOIN
dbo.Contract INNER JOIN
dbo.Customer ON dbo.Contract.customerId = dbo.Customer.customerId ON dbo.Contract_Meter.contractId =
dbo.Contract.contractId INNER JOIN
dbo.Services ON dbo.Meter.serviceId = dbo.Services.serviceId INNER JOIN
dbo.SevicesPricelist ON dbo.Services.serviceId = dbo.SevicesPricelist.serviceId INNER JOIN
dbo.CustomerType ON dbo.Customer.customerTypeId = dbo.CustomerType.customerTypeId INNER JOIN
dbo.CustomerCategory ON dbo.Contract.customerCategoryId = dbo.CustomerCategory.customerCategoryId
tijelo kursora radi update tabele, ali isto se ponaša i kada ne radi ništa, odnosno kad samo iterira... znači ovo je ostalo od njega:
Code:
SET @cursorRowCount = 1
DECLARE myCursor CURSOR
FOR
SELECT customerId, readingId, price, categoryDiscount, readValue, flatDiscount, consumption
FROM dbo.ViewBillingDataPreliminary
ORDER BY customerId, readingId
OPEN myCursor
FETCH NEXT FROM myCursor INTO @customerId, @readingId, @price, @categoryDiscount, @readValue, @flatDiscount, @consumption
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @cursorRowCount
SELECT @cursorRowCount = @cursorRowCount+1
FETCH NEXT FROM myCursor INTO @customerId, @readingId, @price, @categoryDiscount, @readValue, @flatDiscount,
@consumption
END
CLOSE myCursor
DEALLOCATE myCursor;
[Ovu poruku je menjao JustinTime dana 12.03.2009. u 15:30 GMT+1]
[Ovu poruku je menjao JustinTime dana 12.03.2009. u 15:31 GMT+1]