All Forums Database
ac255034 1 post Joined 09/14
28 Jul 2016
Cursor select * with Fetch Next statement

I am working on FETCH STATEMENT inside CURSOR. I need to convert a SQL server script into Teradata.
------------------------------------------------------ ------------------------------------------------------ -----
Following scnerio is working in Teradata( SELECT columns )

SQL SERVER input:---------------------------------------

DECLARE vend_cursor CURSOR  

    FOR SELECT cnic FROM departments;

OPEN vend_cursor  

FETCH NEXT FROM vend_cursor;

Teradata Output: ---------------------------------

replace procedure #anonymous# ()

BEGIN

 

   declare var#0 VARCHAR(100);

   DECLARE vend_cursor CURSOR FOR

   SELECT

         cnic

   FROM departments;

   OPEN vend_cursor;

   FETCH NEXT FROM vend_cursor INTO

      var#0;

END;
------------------------------------------------------ ------------------------------------------------------ -------------

But I need to convert the following script(in which select columns is replaced with Select *)
SQL SERVER input:---------------------------------------

DECLARE vend_cursor CURSOR  

    FOR SELECT * FROM departments;

OPEN vend_cursor  

FETCH NEXT FROM vend_cursor;

Teradata Output: ---------------------------------
 

replace procedure #anonymous# ()

BEGIN

 

   declare var#0 VARCHAR(100);

   DECLARE vend_cursor CURSOR FOR

   SELECT

         cnic

   FROM departments;

   OPEN vend_cursor;

   FETCH NEXT FROM vend_cursor INTO

      var#0;

END;

The output needs to be modified. Now I need to run select * statement, so fetch next needs to be modified. One possible solution in mind is to create a new type of varray and us it in fetch statement after INTO. But that is not working. Can any one please help for possible conversion? 

You must sign in to leave a comment.