stored-proceduressap-iq

Unload Statement not working inside begin end block in Sybase IQ


I've a sybaseiq_file.sql file which contains the below code

   begin
         select col1,col2, ROW_NUMBER() OVER (PARTITION BY col3 ORDER BY col1) as v_order    into #tmptbl from tbl    
        UNLOAD TABLE #tmptbl TO 'Vinoth.dat'
        drop table #tmptbl
    end

I want to push the output of the select statement to a file.

But while executing I'm getting the below error. Please help to resolve this.

 dbisqlc -c "uid=XXX;pwd=XXX;eng=XXX;links=tcpip(host=XXX;port=XXX)" -q sybaseiq_file.sql

Error in file "sybase_fileiq.sql" at line 0
Syntax error near 'UNLOAD' on line 2

Solution

  • Resolved the Issue using the below re written Code

     begin
             select col1,col2, ROW_NUMBER() OVER (PARTITION BY col3 ORDER BY col1) as v_order    into #tmptbl from tbl    
            select * from #tmptbl ># 'Vinoth.dat'
            drop table #tmptbl
        end