title: Teradata FOR CURSOR to SQL Server object
body: <p>I am fairly new to Teradata and I am trying to migrate a big stored procedure to SQL Server (T-SQL). I have a cursor statement (below) which I am trying to make sense. Its a cursor for sure, but the FOR in front is confusing me.</p>
  
  <pre><code>     FOR clmn_cursor2 AS clmn_cursor2 CURSOR FOR
               SELECT LTRIM(RTRIM(cmd.src_attr_txt)) src_attrib,
                                                 case 
                                                 when (CHARINDEX(' as ' ,cmd.src_attr_txt)&gt; 0) 
                                                 then SUBSTRING(cmd.src_attr_txt,CHARINDEX(' as ',LTRIM(cmd.src_attr_txt))+4, LEN(cmd.src_attr_txt))
                                                 else SUBSTRING(cmd.src_attr_txt,CHARINDEX('.' ,LTRIM(cmd.src_attr_txt))+1, LEN(cmd.src_attr_txt))
                                                 end 'col_null_var'
                            FROM  t_srch_res_cfg cmd WHERE cmd.srch_catg_id= @search_cat_id
                            ORDER BY cmd.attr_disp_ord
        DO
               SET @v_select_stmt = @v_select_stmt + clmn_cursor2.src_attrib;
               SET @v_col_null_stmt = (v_col_null_stmt) + 'NULL as ' + (clmn_cursor2.col_null_var)
        END FOR; 
  </code></pre>
  
  <p>What does the above code mean? I figured out the select part, but cant make sense of the FOR CURSOR thing. How best can I implement this on SQL Server 2012?</p>
  
  <p>Thanks.</p>