Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    1

    Unanswered: Sybase iSQL Cursor Issue

    I've created a table called "Directory" with no index.
    I populated it by inserting records and updating fields in that record. This all works fine.

    Now I need to use a cursor to find all appropriate names and email values from the Name table and update the related fields in Directory table.

    There can be from 1 to 15 individual names and associated email values per record, so that is why I have a counter variable and use it to create the field name in the update statement.

    PROBLEM CURSOR:

    DECLARE
    @co_id VARCHAR(15),
    @count INTEGER,
    @full_name VARCHAR(60),
    @email VARCHAR(60)
    SET NOCOUNT ON

    DECLARE AGC_Dir CURSOR FOR
    SELECT n.co_id, n.full_name, n.email
    FROM directory d JOIN name n ON d.co_id = n.co_id JOIN wa_info w ON d.co_id = w.id
    WHERE w.roster = 1

    OPEN AGC_Dir

    FETCH NEXT AGC_Dir INTO @co_id, @full_name, @email
    WHILE @@sqlstatus = 0

    SET @count = 1

    BEGIN
    UPDATE directory
    SET 'ind_fullname' + CONVERT(VARCHAR(2),@count) = @full_name,
    'ind_email' + CONVERT(VARCHAR(2),@count) = @email
    WHERE co_id = @co_id

    SET @count = @count + 1
    SET @full_name = ''
    SET @email = ''
    FETCH NEXT AGC_Dir INTO @co_id
    SET @count = 1
    END
    CLOSE AGC_Dir

    The problem is that I keep getting an error: Error at line 1 Syntax Error near "@co_id"

    I'm good at T-SQL in MS SQL, but I'm not good using iSQL in Sybase Anywhere 6.0.

    Any help is appreciated.

    Thanks!

  2. #2
    Join Date
    Nov 2002
    Location
    Switzerland
    Posts
    524
    Try
    - to remove your SET NOCOUNT ON
    - to decclare your cursor before your variables

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •