Declare local variable in MySQL

Last Reply 5 months ago By dharmendr

Posted 5 months ago

Hi!

How to convert mssql query to mysql

Below code work in mssql. Now I want using its in mysql work branch, but its show error in declare variable.

How I can use it in mysql?

Can somebody help me for convert it to mysql?

Declare @Price float, @Result float, @IdName int, @IdPerson int, @Year date, @IdProduct bigint, @ResDate int, @Counter int, @IdPrice float, @Name int, @Person int, @GetYear date, @GetYearRep date, @GetYearExact date, @Product bigint, @resultdep float, @PriceDep float, @PriceDepId float, @PriceIdNow float, @PriceNowId float,  @monthdep float

SET @Counter = 1
WHILE (@Counter <= (SELECT COUNT(*) FROM tblDepr))
	BEGIN  
		SET @Price = (SELECT Price FROM (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0)) SiNo,Price FROM tblDepr) t WHERE t.SiNo = @Counter)
		SET @PriceDep = (SELECT PriceDep FROM (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0)) SiNo,PriceDep FROM tblDepr) t WHERE t.SiNo = @Counter)
		SET @IdName = (SELECT IdName FROM (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0)) SiNo,IdName FROM tblDepr) t WHERE t.SiNo = @Counter)
		SET @IdPerson = (SELECT IdPerson FROM (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0)) SiNo,IdPerson FROM tblDepr) t WHERE t.SiNo = @Counter)
		SET @Year = (SELECT [Year] FROM (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0)) SiNo,[Year] FROM tblDepr) t WHERE t.SiNo = @Counter)
		SET @IdProduct = (SELECT IdProduct FROM (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 0)) SiNo,IdProduct FROM tblDepr) t WHERE t.SiNo = @Counter)
		begin
			 insert into tblReg([Price], [PriceDep], [IdName], [IdPerson], [Year], [IdProduct])values(@Price, @PriceDep, @IdName, @IdPerson, @Year, @IdProduct)
		end
set @Counter = @Counter + 1
END

 

You are viewing reply posted by: dharmendr 5 months ago.