hhhhhheeeeeelp me out i want to convert mssql query in mysql format
create table #tbl
(
userid INT,
sponsorid INT,
position varchar(10),
IsUpdated INT ,
IsSelected INT
)as set nocount ON
declare LeftCount INT
declare RightCount INT
insert into #tbl
select userid,sponsorid,position,null,null
from table1
where sponsorid = 1
while ((select count(1) from #tbl where IsUpdated is null)>1)
begin
update #tbl set IsSelected=1
insert into #tbl
select table1.userid,table1.sponsorid,#tbl.position,null, null
from table1
inner join #tbl
on #tbl.userid = table1.sponsorid
where #tbl.IsUpdated is null
update #tbl set IsUpdated = 1 where IsSelected=1
end
set @LeftCount = (select count(userid) from #tbl where position = 'Left')
set @RightCount = (select count(userid) from #tbl where position = 'Right')
select @LeftCount as lcount,@RightCount as rcount,(@LeftCount) * 250 as leftS ,(@RightCount) * 250 as RightS
select * from #tbl
drop table #tbl |