Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic Select for CURSOR

Author  Topic 

dewacorp.alliances

452 Posts

Posted - 2008-05-14 : 02:44:04
Hi all

I am trying to do dynamic Select for Cursor. The dynamic would be like this:
IF CONDITION1 IS TRUE: 
SELECT CustomerTenderID, CustomerSiteID, ContractPeriod, SupplierID
FROM dbo.tnd_TenderSiteRateConsumptionView
WHERE CustomerTenderID = @CustomerTenderID

IF CONDITION2 IS TRUE:
SELECT CustomerTenderID, CustomerSiteID, ContractPeriod, SupplierID
FROM dbo.tnd_TenderSiteRateConsumptionView
WHERE CustomerTenderID = @CustomerTenderID AND
CustomerSiteID = @CustomerSiteID


etc etc

Here's the cursor


DECLARE RateList CURSOR FOR
SELECT CustomerTenderID, CustomerSiteID, ContractPeriod, SupplierID
FROM dbo.tnd_TenderSiteRateConsumptionView
WHERE (BASED ON CONDITION)
ORDER BY CustomerTenderID,
CustomerSiteID,
SupplierID,
ContractPeriod

OPEN RateList
FETCH NEXT FROM RateList
INTO @CustomerTenderID, @ReturnedCustomerSiteID, @ReturnedContractPeriod, @ReturnedSupplierID
WHILE @@FETCH_STATUS = 0
BEGIN
SET @rowNum = @rowNum + 1

-- DO SOME FUNKY STUFF


FETCH NEXT
FROM RateList
INTO @CustomerTenderID, @ReturnedCustomerSiteID, @ReturnedContractPeriod, @ReturnedSupplierID

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-14 : 02:46:58
Why are using cursor? can i ask what your requirement?
Go to Top of Page

dewacorp.alliances

452 Posts

Posted - 2008-05-14 : 02:52:20
It's a complex query I would say and the best approach is using CURSOR. It's construct in such away for the reporting services.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-14 : 04:04:33
quote:
Originally posted by dewacorp.alliances

It's a complex query I would say and the best approach is using CURSOR. It's construct in such away for the reporting services.



Can you post your requirement. I think you can deal it in a set based approach.
Go to Top of Page

dewacorp.alliances

452 Posts

Posted - 2008-05-14 : 08:29:25
Hi Visakh

As I said on the first post, whether it is possible or not to have a dynamic SELECT for cursor based on the condition. I am thinking to have SQL query construction that I can passed on.

Go to Top of Page
   

- Advertisement -