`
wfzhanga
  • 浏览: 70212 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

回家看看...

阅读更多
USE [MichelinTB]
GO
/****** Object:  StoredProcedure [dbo].[ps_process_retread_serial_number]    Script Date: 12/24/2010 16:19:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ps_process_retread_serial_number]
AS
BEGIN
	
	DECLARE @bonusPointSilver INT 
	DECLARE @bonusPointGolden INT 
	SELECT @bonusPointSilver = ISNULL(parameter_value_int,1500) FROM dbo.parameter_value WHERE parameter_value_id = 51
	SELECT @bonusPointGolden = ISNULL(parameter_value_int,2500) FROM dbo.parameter_value WHERE parameter_value_id = 52
	
	UPDATE imp_retread_tyre_serial_number 
		SET process_status = 3,
			process_time = GETDATE(),
			error_code = 1,
			remark = 'Serial number does not exist!'
	WHERE 1=1
	AND ISNULL(process_status, 0)= 0
	AND NOT EXISTS (SELECT 1 FROM dbo.transaction_claim_details tcd 
		WHERE tcd.serial_no = imp_retread_tyre_serial_number.serial_number)
	
	
	IF OBJECT_ID('tempdb..#retreadTyres') IS NOT NULL 
		DROP TABLE #retreadTyres
	
	SELECT 
		irtsn.imp_retread_tyre_serial_number_id,
		irtsn.serial_number,
		acc.account_id, 
		ISNULL(acc.account_class_id, 1) account_class_id,
		acc.account_class_start_date,
		irtsn.retread_date,
		CASE WHEN ISNULL(acc.account_class_id, 1) = 1 THEN 2
		     WHEN ISNULL(acc.account_class_id, 1) IN (2,3) AND CONVERT(VARCHAR(10), acc.account_class_start_date, 120) > CONVERT(VARCHAR(10),irtsn.retread_date, 120) THEN 3
		ELSE 1 END flag,
		CASE WHEN ISNULL(acc.account_class_id, 1) = 2 THEN @bonusPointSilver
			 WHEN ISNULL(acc.account_class_id, 1) = 3 THEN @bonusPointGolden
		ELSE 0 END points
	INTO #retreadTyres
	FROM imp_retread_tyre_serial_number irtsn 
		JOIN dbo.transaction_claim_details tcd ON irtsn.serial_number = tcd.serial_no
		JOIN dbo.transaction_claim tc ON tcd.transaction_claim_id = tc.transaction_claim_id
		JOIN account acc ON acc.account_id = tc.purchase_account_id
	WHERE 1=1
		AND tc.processed_status IN (1,2)
		AND tcd.check_results IN (1,4)
		AND irtsn.active_flag = 1
		AND ISNULL(irtsn.process_status, 0) IN (0, 3)
	

	UPDATE rt
		SET rt.flag = 4
	 FROM #retreadTyres rt 
	 WHERE 1=1
	 AND rt.flag = 1
	 AND EXISTS (SELECT 1 FROM operation op 
						WHERE 1=1
						AND op.points_type_id = 26 
						AND op.account_id = rt.account_id
						AND op.remark = rt.serial_number
		)

	UPDATE imp_retread_tyre_serial_number 
		SET process_status = 2,
			process_time = GETDATE(),
			error_code = 2,
			remark = 'This account is not a silver or golden account!'
	 FROM #retreadTyres rt 
	 JOIN imp_retread_tyre_serial_number irtsn ON rt.imp_retread_tyre_serial_number_id = irtsn.imp_retread_tyre_serial_number_id
	 WHERE 1=1
	 AND rt.flag = 2
	 
	UPDATE imp_retread_tyre_serial_number 
		SET process_status = 2,
			process_time = GETDATE(),
			error_code = 3,
			remark = 'Class start date is later than retread date!'
	 FROM #retreadTyres rt 
	 JOIN imp_retread_tyre_serial_number irtsn ON rt.imp_retread_tyre_serial_number_id = irtsn.imp_retread_tyre_serial_number_id
	 WHERE 1=1
	 AND rt.flag = 3
	 
	 UPDATE imp_retread_tyre_serial_number 
		SET process_status = 2,
			process_time = GETDATE(),
			error_code = 4,
			remark = 'This serial number retread points has been added!'
	 FROM #retreadTyres rt 
	 JOIN imp_retread_tyre_serial_number irtsn ON rt.imp_retread_tyre_serial_number_id = irtsn.imp_retread_tyre_serial_number_id
	 WHERE 1=1
	 AND rt.flag = 4
	
	UPDATE imp_retread_tyre_serial_number 
		SET process_status = 1,
			process_time = GETDATE(),
			error_code = 0,
			remark = 'OK'
	 FROM #retreadTyres rt 
	 JOIN imp_retread_tyre_serial_number irtsn ON rt.imp_retread_tyre_serial_number_id = irtsn.imp_retread_tyre_serial_number_id
	 WHERE 1=1
	 AND rt.flag = 1
	 
	 UPDATE imp_retread_tyre_serial_number 
		SET process_status = 2,
			process_time = GETDATE(),
			error_code = 5,
			remark = 'Serial no status error'
	 WHERE 1=1
	 AND ISNULL(process_status, 0) = 0
	 AND NOT EXISTS(SELECT * FROM #retreadTyres rt WHERE rt.imp_retread_tyre_serial_number_id = imp_retread_tyre_serial_number.imp_retread_tyre_serial_number_id)
	 
	 
	 INSERT INTO dbo.operation (
	 	operation_status,create_by,setting_by,
	 	setting_time,transaction_time,
	 	points,
		create_time,transaction_date,
	 	expire_date,external_transaction_id,
	 	account_id,
	 	points_type_id,
	 	remark
	 ) 
	 SELECT 
		'A', 1, 1, 
		GETDATE(), rt.retread_date, rt.points,
		GETDATE(), rt.retread_date, 
		dbo.f_get_expire_date_for_member(convert(varchar(30),rt.retread_date,120)),
		rt.imp_retread_tyre_serial_number_id,
		rt.account_id, 26, rt.serial_number
	 FROM #retreadTyres rt 
	 WHERE 1=1
	 AND rt.flag = 1
	 
	 UPDATE acc 
		SET acc.points_available_balance = isnull(acc.points_available_balance, 0) + ISNULL(t.total_points, 0),
		    acc.points_earned = isnull(acc.points_earned,0) + ISNULL(t.total_points, 0),
		    acc.setting_by = 1,
			acc.setting_time = getdate()
	 FROM (
		SELECT account_id, SUM(points) total_points FROM #retreadTyres rt
		WHERE 1=1
		AND flag = 1
		GROUP BY account_id
	 ) t 
	 JOIN account acc ON acc.account_id = t.account_id
END









-- drop PROCEDURE ps_process_retread_account_segmentation
ALTER PROCEDURE [dbo].[ps_process_retread_account_segmentation]
	-- Add the parameters for the stored procedure here
AS
BEGIN

	IF OBJECT_id('tempdb..#account_segmentation') IS NOT NULL 
		DROP TABLE #account_segmentation
	
	SELECT 
		imp_account_segmentation_id,
		account_code,
		segmentation_value
	INTO #account_segmentation
	FROM imp_account_segmentation ias
	WHERE 1=1
	AND (ias.process_status IS NULL OR ias.process_status = 0)
	
	--== Account NOT Found
	UPDATE ias 
		SET ias.process_status = 2,
		ias.process_time = GETDATE(),
		remark = 'Account NOT Found'
	FROM #account_segmentation tas
	JOIN imp_account_segmentation ias ON tas.imp_account_segmentation_id = ias.imp_account_segmentation_id
	WHERE 1=1
	AND NOT EXISTS(SELECT 1 FROM account acc WHERE acc.account_code = ias.account_code)
	
	
	--== Update imp_account_segmentation
	UPDATE ias 
		SET ias.process_status = 1,
			ias.process_time = GETDATE()
	FROM #account_segmentation tas
	JOIN imp_account_segmentation ias ON tas.imp_account_segmentation_id = ias.imp_account_segmentation_id
	JOIN account acc ON acc.account_code = ias.account_code
	WHERE 1=1
	
	UPDATE acc 
		SET acc.segmentation_setting_by = 1,
			acc.segmentation_setting_time = GETDATE(),
			acc.segmentation=ias.segmentation_value
	FROM #account_segmentation tas
	JOIN imp_account_segmentation ias ON tas.imp_account_segmentation_id = ias.imp_account_segmentation_id
	JOIN account acc ON acc.account_code = ias.account_code
	WHERE 1=1
	AND ias.process_status = 1
	
	IF OBJECT_id('tempdb..#account_segmentation') IS NOT NULL 
		DROP TABLE #account_segmentation
		
END

















分享到:
评论

相关推荐

    常回家看看~剪影动画.fla

    flash源文件,主题为常回家看看,别让父母等太久,剪影类型的小作品,有动画补间,有逐帧,有音乐,文件为源文件,可以自行修改调整,也可以当做学习参考

    常回家看看作文.doc

    这篇文档标题为“常回家看看作文.doc”,实际上是一篇关于孝道和家庭关怀的文章,标签为“范文”,意味着这可能是一篇学生写作的示范作品。文章通过一个小故事,阐述了作者对“常回家看看”这一行为的理解和感悟,...

    迎中秋、庆国庆、常回家看看策划书.doc

    迎中秋、庆国庆、常回家看看策划书.doc

    中华美德颂.docx

    正如歌中所唱,“找点空闲,抽点时间,领着孩子常回家看看...”,这首歌曲倡导的不仅仅是回访亲人,更是呼唤人们将孝道精神传承下去,让它在现代社会中保持活力。 中华美德中的“孝”文化,不仅是个人品德的体现,...

    【K12提高】K12七年级音乐下册第3单元《常回家看看》教学设计花城版.pdf

    【K12提高】K12七年级音乐下册第3单元《常回家看看》教学设计花城版.pdf

    小班数学 连连看看.doc

    【小班数学连连看看——探索长方形】 小班数学活动“连连看看”旨在帮助幼儿深入理解和辨认几何形状,特别是长方形。通过一系列有趣且互动的教学环节,孩子们将在比较和操作中逐步认识长方形的特性,并能区分它与...

    就哥偶寄回家来看看链接7za.exe

    快捷键护理记录和客户

    说课:把垃圾带回家.doc

    本次教学活动的主题为"把垃圾带回家",主要针对小班的孩子进行,旨在培养他们良好的卫生习惯,了解垃圾分类的重要性,并树立保护环境的意识。教学设计注重结合儿童的生活经验和直观感知,通过多媒体教学手段和互动...

    200元802.11n无线路由器捧回家.pdf

    接下来,我们来看看802.11n无线路由器的一些特点。文中提到的腾达W307R Wireless-N路由器是一款时尚、精致的802.11n产品,它的安装和设置相对简便,尤其是首创了光盘安装方式,让普通用户也能轻松完成网络设置。此外...

    成功寓言抬着毛驴回家.doc

    首先,从技术的角度看,这个寓言可以映射到软件开发过程中的决策制定。在开发项目时,开发者可能会面临来自各方的压力,包括用户、管理层、同行甚至自己的团队成员。他们可能会对功能设计、技术选型或实现方式提出...

    回家学习 story.docx

    3. **课程记录功能**:这个功能使得用户能够保存和追踪已学习的课程,方便以后回看和复习。用户可以轻松切换不同课程,避免在众多内容中迷失,同时也能提高学习效率。 4. **课内知识要点提炼功能**:该功能对教材或...

    回家高二作文.docx

    根据给定文件的信息来看,这份文档实际上是一组由多个独立作文组成的文本集合,主题围绕“回家”的情感体验展开。下面将从这些作文中提取出相关的知识点,并进行详细阐述。 ### 回家的意义与情感表达 #### 一、...

    假如不带书包回家作文.doc

    随后,作者提到了玩电脑、看电视、打电子游戏等娱乐活动,这些都是现代儿童常见的休闲方式,反映出他们在课业压力之外追求快乐的一面。此外,他也表达了对舒适生活的渴望,比如洗澡、调整空调温度后惬意地休息,这...

    《平安回家》安全课教案.doc

    4. 如何过马路:讲解在不同情况下如何安全过马路,如一停二看三通过,理解交通信号灯的意义,以及在没有交通标志的地方如何安全通行。并强调了与行驶中的车辆保持适当距离的重要性。 5. 交通安全标语:课程中引入了...

    《垃圾的家》环境教案4——送垃圾宝宝回家.doc

    在“看谁做得对”游戏中,活动进一步强化了学习效果。首先,通过课件互动游戏“送垃圾宝宝回家”,幼儿观看动画并尝试将垃圾放入正确的垃圾桶,这不仅提升了他们的参与度,也检验了他们对垃圾分类的理解。其次,分组...

    CoralLang_chs.dll

    CoralLang_chs.dll 回家看看来看看里面空间和科技交流

    幼儿园精品说课稿《垃圾回家》含反思.docx

    7. 活动流程设计:分为了解垃圾来源、理解垃圾处理方法、实际操作送垃圾“回家”三个环节,逐步引导幼儿形成正确的环保行为。 8. 教育延伸:鼓励幼儿将所学应用于日常生活,如在家中实践垃圾分类,成为环保小卫士,...

    二年级数学上册 回家路上教案 北师大版 教案.doc

    这篇文档是针对小学二年级数学课程的一份北师大版教案,主要涵盖了“回家路上”这一教学主题。教案的设计旨在通过一系列活动,帮助学生掌握和巩固乘法口诀的应用,同时提升他们的数学思维能力和表达能力。 教学目标...

    二年级数学上册 回家路上 2教案 北师大版 教案.doc

    2. 进行比赛,看谁能快速找到正确答案,强化视觉识别和逻辑推理能力。 **摘星星** 要求学生理解图意,根据题目列出乘法或加法算式,锻炼他们在实际问题中应用数学知识的能力。 **对口令** 写出得数为20的算式...

Global site tag (gtag.js) - Google Analytics