The SQL stored procedure to MySQL

USE [beone]
GO
/****** Object: StoredProcedure [dbo].[empCusInd] script date: 03/04/2011 16:26:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author: GM
-- Create date: 2011-2-21
Description: customer industry statistics
-- =============================================
CREATE PROCEDURE [dbo].[empCusInd](
@sqlAppend varchar(8000)
)
AS
BEGIN
- statement string variables, for dynamic assembly
declare @sql varchar(max),@sql1 varchar(8000)
-- Customer industry into a temporary table columns
set @sql1='select typ_name as sta_name into ##tempCusInd
from cus_cor_cus left join type_list on cor_ind_id=typ_id where cor_isdelete=''1'' group by typ_name order by typ_name desc'

if object_id('tempdb..##tempCusInd') is not null
begin
drop table ##tempCusInd
end
exec(@sql1)

The SQL command -- assembly
set @sql = 'select se_no,max(se_code),max(se_name) as head'
- customer industry rotation meter
select @sql = @sql +
case when sta_name is not null then
', sum(case typ_name when '''+sta_name+''' then 1 else 0 end) ['+sta_name+']'
else
', sum(case when typ_name is null then 1 else 0 end) As is not selected'
end from (select sta_name from ##tempCusInd)as a
- plus together
select @sql = @sql+',
count(cor_code)As together
from cus_cor_cus inner join sal_emp on cor_se_no=se_no left join type_list on cor_ind_id=typ_id
where cor_isdelete=''1'' ' + @sqlAppend
+ ' group by se_no with rollup'
--print(@sql)
exec(@sql)
END


Also please God exhibitions! What precautions, thank you

Started by Theodore at November 29, 2016 - 8:43 AM

Refer to MYSQL official free manual, first try to revise, then what specific problems will write your own statements and false information to post for discussion.

Posted by Cher at December 12, 2016 - 9:10 AM

I was a rookie... I don't know how to change a Mysql stored procedure! Also hope who will help! Thanks a million

Posted by Theodore at December 20, 2016 - 9:40 AM

You look MySQL syntax to slowly change

Posted by Nicole at January 02, 2017 - 10:38 AM

After the scan scripts, suggested that the reference to MYSQL dynamic SQL + preprocessor statements rectification

Case uses the instance and MYSQL dynamic SQL

Posted by Abby at January 03, 2017 - 10:56 AM

What God will trouble help me revise! Be indebted forever.

Posted by Theodore at January 14, 2017 - 11:16 AM