Click here to Skip to main content
15,902,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends ,this is a mysql procedure to copy a table data in temp table .I have not work in mysql.Can yuo please help me in converting it to sql server procedure
.Thanks in advance freinds.

SQL
CREATE  PROCEDURE sp_category_select3()
as BEGIN
declare done int default 0
declare categoryid int
declare categoryname varchar(100)
declare groupunderid int
declare groupundername varchar(50)
declare alias varchar(100)
declare supercategory varchar(100)
declare NotZero int default 0
declare cur1 cursor for select c.lcategoryid, c.ccategoryname, c.lundercategoryid,
 c.calias, s.csupercategoryname from category c inner join supercategory s on
  c.lsupercategoryid=s.lsupercategoryid where c.bdeleteflag=0
declare continue handler for not found set done = 1
drop table if exists temptablecategory
create temporary table temptablecategory(cat_id int, cat_name varchar(100), 
cat_underid int, cat_under_group varchar(100), cat_alias varchar(100), cat_super varchar(100))
open cur1
  repeat
    fetch cur1 into categoryid, categoryname, groupunderid, alias, supercategory
    set groupundername=""
        if not done Begin
       if groupunderid=0  Begin
            set groupundername=""
                   	       
       	 elseif groupunderid<>0 Begin
           set groupundername=(select distinct c.ccategoryname as undercategoryname from category as c inner join category as d on c.lcategoryid=d.lundercategoryid where d.lundercategoryid=groupunderid and c.bdeleteflag=0) 
                
         End  
        insert into temptablecategory values(categoryid, categoryname, groupunderid,groupundername, alias, supercategory)
          End
  until done end repeat
	
   close cur1
 select * from temptablecategory drop table temptablecategory
    END */$$
 
Go
Posted
Updated 3-Nov-11 0:05am
v3

1 solution

the syntax is not very different for MySQL. your code uses cursor& you can check the following code as a reference for cursors in MySQL:

http://www.java2s.com/Tutorial/MySQL/0240__Cursor/Usingwhilelooptoloopthroughacursor.htm[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900