Cursor loop for all values inside case

Posted on 2007-08-09
Last Modified: 2013-11-05
Is there a way I can loop through when district count > 1, and get all District Values
Something of the kind DSDC.DistrictValue(0) + DSDC.DistrictValue(1) + DSDC.DistrictValue(2) ...

            WHEN DSDC.DistrictCount > 1 THEN
                  DSDC.DistrictValue + '*'  -- I need to loop here for all values
      END As DistrictCourt

Appreciate the Help
Question by:vbothello
    LVL 2

    Expert Comment

    Is this a SQL Server question ?
    LVL 8

    Accepted Solution

    Do you want to list all the Different District values together?
    Create function fnDistrict(@Distrinct as int)
    Returns Varchar(1000)
    Declare @DistrictValue Varchar(1000)
    SET @DistrictValue = ''
    SELECT @DistrictValue = @DistrictValue + ', ' + DistrictValue From DSDC where District = @District
    Return Left(@DistrictValue,  Len(@DistrictValue) -2)

    Use this function in the select and pass each district as

    Select Col1, Col2, dbo.fnDistrict(District) from DSDC

    Author Comment

    This is a SQL Server question, The Case statement is just a part of the query (DSDC, DSPS is the table name already defined )
                WHEN DSDC.DistrictCount > 1 THEN
                      DSDC.DistrictValue + '*'
          END As DistrictCourt
                WHEN DSPS.DistrictCount > 1 THEN
                      DSPS.DistrictValue + '*'
          END As PSC

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now