Should i use cursor

  • Hi Gurus,
     
    This is my first post here and I am new to SQL Server as well. The issue that I am facing is this. I ahve been assigned a legacy sql project. There is a table in the databse that has the output as:
     
    col1     col2     col3     col4     col5     col6
     
    NULL     123     NULL     321    NULL     qwjk
    dg        NULL    hghy     NULL   qwh     NULL
    NULL     eyde   NULL     hggwd  NULL    qjwh
    seu       NULL    qw      NULL    ygd      NULL
    .
    .
    .
    and so on
     
    as you can observe, each row has a NULL value and an actual value. The source query is inputting a null value and then an actual value(maybe sum() aggregate function is being used earlier in the source query). The actual output should be
     
    col1   col2    col3    col4    col5    col6
     
    dg     123     hghy   321    qwh     qwjk
    seu   eyde    qw     hggwd ygd     qjwh
    .
    .
    and so on
     
    I am planning to use a cursor, derieving each value of a column from each row and updating the NULL value with the actual value. Is there any better way to do so, I have seen deppressing comments about usage of cursors in SQL queries.
     
    Happy coding,
    Sachin
  • Hi Joe,
     
    True as it is, the design as well as the schema is really confusing for me, partly because of the project being a legacy one with ASP code being used and ASP.net pages emerging out from them. The SQL being used is equally incomprehensible. Excessive use of Cursors and temprory tables and triggers is being implemented. Though it is true that I should have posted the schema of the table, but I wanted to be as concise as possible. The SQL query that I am facing consists of not less than 8 tables being joined in different ways(left outer and inner). Though I have implemeted the cursor succesfully in the query, I just wanted to be more object oriented, trying to make the query more optimised thus trying to minimise the use of cursors, triggers and temp tables. I appreciate your help and once again thanks for the help to one and all who took their time out from their busy schedule.
     
     
    Regards,
    Sachin

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply