sqlserver 創建帶返回值的存儲過程

--創建存儲過程
ALTER PROCEDURE [dbo].[pro_sales_month]
  @yearMonth varchar(30),
  @returnValue VARCHAR(10) output
AS
BEGIN TRY
    BEGIN TRANSACTION

	insert into crm_platform_kingyork_staging.dbo.KY_SD_DATA_M
	SELECT 
es.id as	PK_ID,
es.sale_year_month  as STATIS_MONTH,
es.institution_id as	COMPANY_CODE,
'' as ORIG_COMPANY_PRO,
'' as ORIG_COMPANY_CITY,
es.to_institution_name as	ORIG_CUSTOMER_NAME,
'' as ORIG_CUSTOMER_PRO,
'' as ORIG_CUSTOMER_CITY,
es.to_institution_id_format as	CUSTOMER_CODE,
es.product_name as	ORIG_PRODUCT_NAME,
es.product_specs as	ORIG_PRODUCT_ITEM,
es.product_batch_code as	BATCH_NUMBER,
es.product_count_original as	ORIG_NUMBER,
es.unit as	ORIG_UNIT,
es.product_id_format as PRODUCT_ID,
es.price as	PRODUCT_ID,
CONVERT(VARCHAR(10),es.sale_time,21) as	DATE_SD,
'' as UPDATE_STATUS,
'' as SYN_STATUS,
GETDATE() as CREATE_TIME,
'' as MODIFY_TIME,
'' as KY_MODIFY_TIME,
es.collect_type as DATA_SOURCE,
'' as REMARK
from ent_sfl_sale_format es
LEFT JOIN v_slf_institution vi on es.institution_id = vi.institution_id
LEFT JOIN v_slf_institution vif ON es.to_institution_id_format = vif.institution_id
LEFT JOIN v_slf_product vp on es.product_id_format = vp.product_id
LEFT JOIN s_user s on es.uploader_id = s.id
where vi.status = 'ACTIVE'
--  AND vif.status= 'ACTIVE'
--  AND vp.status= 'ACTIVE'
 AND es.deleted= 0 
 AND es.sale_year_month = @yearMonth 
	
	COMMIT TRANSACTION
	set @returnValue = '1'
	return @returnValue
		
END  TRY

BEGIN CATCH
 ROLLBACK TRANSACTION
 set @returnValue = '0'
		return @returnValue
END CATCH

執行存儲過程

declare @returnValue varchar(30)
exec  pro_sales_month '2020-06',@returnValue output
print @returnValue
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章