Search
 
SCRIPT & CODE EXAMPLE
 

SQL

SQL loop with cursor

DECLARE 
    @product_name VARCHAR(MAX), 
    @list_price   DECIMAL;

DECLARE cursor_product CURSOR
FOR SELECT 
        product_name, 
        list_price
    FROM 
        production.products;

OPEN cursor_product;

FETCH NEXT FROM cursor_product INTO 
    @product_name, 
    @list_price;

WHILE @@FETCH_STATUS = 0
    BEGIN
        PRINT @product_name + CAST(@list_price AS varchar);
        FETCH NEXT FROM cursor_product INTO 
            @product_name, 
            @list_price;
    END;

CLOSE cursor_product;

DEALLOCATE cursor_product;
Comment

PREVIOUS NEXT
Code Example
Sql :: psql while loop 
Sql :: ora-01109 database not open in oracle 19c 
Sql :: date format in sql 
Sql :: how to use lower case in mysql 
Sql :: mysql query to check record exists in database table or not 
Sql :: how to fetch first 5 characters in sql 
Sql :: postgresql create schema in specific database 
Sql :: Configure postgresql engine for your django application 
Sql :: update field sql 
Sql :: sql convert xml to text 
Sql :: select and condition in sql 
Sql :: oracle trigger 
Sql :: oracle sql listagg 
Sql :: select row from mysql where date more than 30 days 
Sql :: pl/sql loop example 
Sql :: SQL COUNT() with DISTINCT 
Sql :: convert money to varchar sql server 
Sql :: how to drop all tables in postgresql 
Sql :: oracle create table auto generated primary key 
Sql :: select if then postgresql 
Sql :: oracle nextval 
Sql :: get all columns from table sql 
Sql :: sql stored procedure with output parameters 
Sql :: list of all table names in sql server databse 
Sql :: mysql update join 
Sql :: SELECT exists sql 
Sql :: select milliseconds mysql 
Sql :: sql find duplicate records in two tables 
Sql :: postgres set null 
Sql :: select 2 rows in sql 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =