I need a stored procedure - I have put required scripts -
- I have a requirement to send a notifications who has not acknowledged the email if [nhst].[cas_notify] +7 days.I have to insert values into table - nhst,nmsg based on these tables - f_up_hst,f_up_msg,master
master - It is the master table having subject & body - I have to pick only those rows where [nhst].[ack]=0 (if user acknoweldge then it will be 1 else 0)
- I have to send only 1 notification to the user in a week. This stored procedure will be part of SSIS job and will run on daily basis.
I have a scenario here - A notification should send based on the below scenario
- Initially, I have a requirement to send notification based on [cas_notify]. In this case I have 3 case id's for a empid='e1'
But I should send only case id=1 (earlier) and shouldn't send other notifications even though they fall under criteria, which is cas_notify + 7. - Record should be inserted into these tables - f_up_hst,f_up_msg and subject & body should be picked from master table.
- Next time, If the user 'e1' still didn't respond then on next week, system should send caseid=1,2,3 based on f_ts.f_ts
USE TEST
GO
/****** Object: Table [dbo].[f_up_hst] Script Date: 4/30/2014 12:03:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[f_up_hst](
[f_id] [int] IDENTITY(1,1) NOT NULL,
[empid] [nvarchar](50) NULL,
[caseid] [int] NULL,
[f_u_noteid] [int] NULL,
[f_ts] [datetime] NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[f_up_msg] Script Date: 4/30/2014 12:03:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[f_up_msg](
[f_u_noteid] [int] IDENTITY(1,1) NOT NULL,
[empid] [nvarchar](50) NULL,
[n_email] [nvarchar](50) NULL,
[n_sub] [nvarchar](50) NULL,
[n_body] [nvarchar](50) NULL,
[n_msg_t] [datetime] NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[master] Script Date: 4/30/2014 12:03:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[master](
[n_sub] [nvarchar](50) NULL,
[n_body] [nvarchar](50) NULL,
[id] [int] NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[nhst] Script Date: 4/30/2014 12:03:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[nhst](
[caseid] [int] NULL,
[empid] [nvarchar](50) NULL,
[ename] [nvarchar](50) NULL,
[casename] [nvarchar](50) NULL,
[cas_notify] [datetime] NULL,
[ack] [int] NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[nmsg] Script Date: 4/30/2014 12:03:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[nmsg](
[caseid] [int] NULL,
[n_email] [nvarchar](50) NULL,
[n_sub] [nvarchar](50) NULL,
[n_body] [nvarchar](50) NULL,
[n_msg] [datetime] NULL
) ON [PRIMARY]
GO
INSERT [dbo].[master] ([n_sub], [n_body], [id]) VALUES (N'email', N'this is', 1)
GO
INSERT [dbo].[nhst] ([caseid], [empid], [ename], [casename], [cas_notify], [ack]) VALUES (1, N'e1', N'dinu', N'test1', CAST(0x0000A27300000000 AS DateTime), 0)
GO
INSERT [dbo].[nhst] ([caseid], [empid], [ename], [casename], [cas_notify], [ack]) VALUES (2, N'e1', N'dinu', N'test2', CAST(0x0000A27400000000 AS DateTime), 0)
GO
INSERT [dbo].[nhst] ([caseid], [empid], [ename], [casename], [cas_notify], [ack]) VALUES (3, N'e1', N'dinu', N'test3', CAST(0x0000A27500000000 AS DateTime), 0)
GO
INSERT [dbo].[nhst] ([caseid], [empid], [ename], [casename], [cas_notify], [ack]) VALUES (4, N'e4', N'esh', N'test4', CAST(0x0000A27400000000 AS DateTime), 1)
GO
INSERT [dbo].[nhst] ([caseid], [empid], [ename], [casename], [cas_notify], [ack]) VALUES (5, N'e5', N'dinesh', N'test5', CAST(0x0000A28100000000 AS DateTime), 0)
GO
INSERT [dbo].[nhst] ([caseid], [empid], [ename], [casename], [cas_notify], [ack]) VALUES (6, N'e6', N'kalva', N'test6', CAST(0x0000A28600000000 AS DateTime), 1)
GO
INSERT [dbo].[nmsg] ([caseid], [n_email], [n_sub], [n_body], [n_msg]) VALUES (1, N'dinu@test.com', N'email - test1', N'this is test1', CAST(0x0000A27300000000 AS DateTime))
GO
INSERT [dbo].[nmsg] ([caseid], [n_email], [n_sub], [n_body], [n_msg]) VALUES (2, N'dinu@test.com', N'email - test2', N'this is test2', CAST(0x0000A27400000000 AS DateTime))
GO
INSERT [dbo].[nmsg] ([caseid], [n_email], [n_sub], [n_body], [n_msg]) VALUES (3, N'dinu@test.com', N'email - test3', N'this is test3', CAST(0x0000A27500000000 AS DateTime))
GO
INSERT [dbo].[nmsg] ([caseid], [n_email], [n_sub], [n_body], [n_msg]) VALUES (4, N'esh@test.com', N'email -esh', N'this is esh', CAST(0x0000A27400000000 AS DateTime))
GO
INSERT [dbo].[nmsg] ([caseid], [n_email], [n_sub], [n_body], [n_msg]) VALUES (5, N'dinesh@test.com', N'email - dinesh', N'this is dinesh testing', CAST(0x0000A28100000000 AS DateTime))
GO
INSERT [dbo].[nmsg] ([caseid], [n_email], [n_sub], [n_body], [n_msg]) VALUES (6, N'kalva@test.com', N'email - kalva', N'this is kalva test', CAST(0x0000A28600000000 AS DateTime))
GO