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
分享到:
相关推荐
flash源文件,主题为常回家看看,别让父母等太久,剪影类型的小作品,有动画补间,有逐帧,有音乐,文件为源文件,可以自行修改调整,也可以当做学习参考
"常回家看看作文.doc" 这篇范文以富有情感的语言和生动的故事,提醒我们孝敬父母、关爱家庭的重要性,告诉我们在追求个人成功的同时,不应忽视亲情的价值。 文章通过描述一个感人的小故事展开叙述。当作者的爷爷离...
迎中秋、庆国庆、常回家看看策划书.doc
像流行歌曲中唱到的,“找点空闲,抽点时间,领着孩子常回家看看...”,这种对亲情的呼唤其实就是在提醒我们,孝顺不只是一个概念,更是一种行动的召唤。在繁忙的生活中,我们应抽出时间,关心父母,照顾家人,这才...
【K12提高】K12七年级音乐下册第3单元《常回家看看》教学设计花城版.pdf
【小班数学连连看看——探索长方形】 小班数学活动“连连看看”旨在帮助幼儿深入理解和辨认几何形状,特别是长方形。通过一系列有趣且互动的教学环节,孩子们将在比较和操作中逐步认识长方形的特性,并能区分它与...
快捷键护理记录和客户
本次教学活动的主题为"把垃圾带回家",主要针对小班的孩子进行,旨在培养他们良好的卫生习惯,了解垃圾分类的重要性,并树立保护环境的意识。教学设计注重结合儿童的生活经验和直观感知,通过多媒体教学手段和互动...
接下来,我们来看看802.11n无线路由器的一些特点。文中提到的腾达W307R Wireless-N路由器是一款时尚、精致的802.11n产品,它的安装和设置相对简便,尤其是首创了光盘安装方式,让普通用户也能轻松完成网络设置。此外...
首先,从技术的角度看,这个寓言可以映射到软件开发过程中的决策制定。在开发项目时,开发者可能会面临来自各方的压力,包括用户、管理层、同行甚至自己的团队成员。他们可能会对功能设计、技术选型或实现方式提出...
3. **课程记录功能**:这个功能使得用户能够保存和追踪已学习的课程,方便以后回看和复习。用户可以轻松切换不同课程,避免在众多内容中迷失,同时也能提高学习效率。 4. **课内知识要点提炼功能**:该功能对教材或...
根据给定文件的信息来看,这份文档实际上是一组由多个独立作文组成的文本集合,主题围绕“回家”的情感体验展开。下面将从这些作文中提取出相关的知识点,并进行详细阐述。 ### 回家的意义与情感表达 #### 一、...
随后,作者提到了玩电脑、看电视、打电子游戏等娱乐活动,这些都是现代儿童常见的休闲方式,反映出他们在课业压力之外追求快乐的一面。此外,他也表达了对舒适生活的渴望,比如洗澡、调整空调温度后惬意地休息,这...
我看了看手表,时间还很充裕,这让我更加放心。我想,这也是对自己时间管理能力的一种锻炼吧。 终于,当我转过那个熟悉的街角,看到家的那一刻,我的心里充满了喜悦。我知道,这不仅仅是到达目的地的喜悦,更是对...
剧中,幽默元素的运用恰到好处,既增加了戏剧的可看性,也深化了主题。父亲对世界末日的调侃,母亲对成成迟迟未归的担忧,以及成成和欢欢之间的趣事,都让人在笑声中感受到家的温馨和亲情的力量。 此外,剧本还巧妙...
综合来看,"动物大世界——送动物回家"这一主题活动是对儿童教育的一个有益尝试,它将复杂的生物学知识融入到生动的活动中,让孩子们在实践中学习并培养各种技能。这种教育模式不仅能让孩子们增长见识,更重要的是,...
在动物园这个小社会中,小企鹅的生活原本看起来无忧无虑。然而,内心的呼唤让它的每一步都显得沉重。它对南极那片被冰山和白雪覆盖的家园的思念,是如此的强烈和清晰。这份情感,无论是在人类还是动物之间,都是一条...
为了巩固学习效果,教案中设计了名为“看谁做得对”的互动游戏。在这个游戏中,幼儿将观看动画,并尝试将垃圾放入正确的垃圾桶中,这种参与式的学习方式大大提高了幼儿的参与度和兴趣。分组区域游戏则让孩子们在实际...
接下来的“看一看”环节,教师鼓励学生细致观察主题图,并尝试描述画面中的数学元素,如道路、行人、车辆等,以锻炼学生的观察能力和语言表达能力。随后的“说一说”环节,教师引导学生针对画面提出相关的数学问题,...