Have a problem with using cursors in SQL server enterprise manager

Discussion in 'ASP .Net' started by TaeHo Yoo, Jun 26, 2003.

  1. TaeHo Yoo

    TaeHo Yoo Guest

    Have a problem with using cursors in SQL server enterprise manager.
    My code sql query is followed
    ---------------------------------------
    DECLARE @element_name varchar(100)
    DECLARE elements_cursor CURSOR FOR
    SELECT element_name
    FROM KB_Element_Ref

    OPEN elements_cursor
    FETCH NEXT FROM elements_cursor INTO @element_name

    WHILE @@FETCH_STATUS = 0
    BEGIN
    PRINT @element_name
    FETCH NEXT FROM elements_cursor INTO @element_name
    END

    CLOSE elements_cursor
    DEALLOCATE elements_cursor
    ------------------------------------------------------------
    I have more than 100 rows int KB_Element_Ref table.
    but when I execute this query, it said only a row has affected and did't
    print any element_name.
    does any one know what is going on?


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    TaeHo Yoo, Jun 26, 2003
    #1
    1. Advertising

  2. your code is correct

    are you sure the table is not empty?

    Vaclav

    "TaeHo Yoo" <> wrote in message
    news:...
    > Have a problem with using cursors in SQL server enterprise manager.
    > My code sql query is followed
    > ---------------------------------------
    > DECLARE @element_name varchar(100)
    > DECLARE elements_cursor CURSOR FOR
    > SELECT element_name
    > FROM KB_Element_Ref
    >
    > OPEN elements_cursor
    > FETCH NEXT FROM elements_cursor INTO @element_name
    >
    > WHILE @@FETCH_STATUS = 0
    > BEGIN
    > PRINT @element_name
    > FETCH NEXT FROM elements_cursor INTO @element_name
    > END
    >
    > CLOSE elements_cursor
    > DEALLOCATE elements_cursor
    > ------------------------------------------------------------
    > I have more than 100 rows int KB_Element_Ref table.
    > but when I execute this query, it said only a row has affected and did't
    > print any element_name.
    > does any one know what is going on?
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Vaclav Jedlicka, Jun 26, 2003
    #2
    1. Advertising

  3. TaeHo Yoo

    Rhys Gravell Guest

    Try
    <CODE>
    DECLARE @element_name varchar(100)
    DECLARE elements_cursor CURSOR FOR SELECT element_name FROM
    KB_Element_Ref

    SELECT COALESCE(element_name,'Null Value') FROM KB_Element_Ref

    OPEN elements_cursor
    FETCH NEXT FROM elements_cursor INTO @element_name
    WHILE @@FETCH_STATUS = 0

    BEGIN
    PRINT '<<' + @element_name + '>>'
    FETCH NEXT FROM elements_cursor INTO @element_name
    END

    CLOSE elements_cursor
    DEALLOCATE elements_cursor
    </CODE>

    in query analyzer to help check if a zero length string, or null is
    being returned.


    Rhys Gravell

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Rhys Gravell, Jun 26, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mamcx
    Replies:
    1
    Views:
    427
    karim
    Jul 18, 2003
  2. bruce barker
    Replies:
    0
    Views:
    467
    bruce barker
    Jul 18, 2003
  3. John
    Replies:
    7
    Views:
    407
    Scott Allen
    Apr 5, 2005
  4. Edward
    Replies:
    4
    Views:
    4,660
    William \(Bill\) Vaughn
    Apr 10, 2006
  5. Cirene
    Replies:
    0
    Views:
    672
    Cirene
    May 21, 2008
Loading...

Share This Page