skip to Main Content

I Have to create two-column different value with the same data, important thing data is from combining two tables with the inner join Statement. Here are the table1 and table 2 (it’s like attendance report)
Am attaching tables
Table 1
Create a table

    * table 1 *
    CREATE TABLE [dbo].[tsStudAttandance](
        [IDNo] [int] IDENTITY(1,1) NOT NULL,
        [StudentName] [varchar](300) NULL,
        [TrainnerName] [varchar](100) NULL,
        [Date] September 19, 2019 NULL,
        [InTime] [varchar](50) NOT NULL,
        [Weekday] [varchar](50) NULL,
        [OutTime] [varchar](50) NULL,
        [StudListId] [int] NULL,
     CONSTRAINT [PK_tsAttandance] PRIMARY KEY CLUSTERED 
    (
        [IDNo] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]


 /* INSERT QUERY NO: 1 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
1, 'Ms.Eva', 'John', '8/12/2019', '9:00 AM', 'Monday', '1:00 PM', 1, 4.00, 1
);

/* INSERT QUERY NO: 2 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
2, 'Mr.Stev Job', 'John', '8/12/2019', '11:00 AM', 'Monday', '1:00 PM', 3, 2.00, 3
);

/* INSERT QUERY NO: 3 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
3, 'Mr.Bill Gate', 'John', '8/12/2019', '9:00 AM', 'Monday', '11:00 AM', 4, 2.00, 3
);

/* INSERT QUERY NO: 4 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
4, 'Mr.Krish', 'Stev', '8/12/2019', '9:00 AM', 'Monday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 5 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
5, 'Mr.Chisty', 'Stev', '8/12/2019', '5:00 PM', 'Monday', '7:00 PM', 6, 2.00, 3
);

/* INSERT QUERY NO: 6 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
6, 'Mr.Micky', 'Stev', '8/12/2019', '11:00 AM', 'Monday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 7 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
7, 'Ms.Victorya', 'John', '8/12/2019', '5:00 PM', 'Monday', '7:00 PM', 9, 2.00, 3
);

/* INSERT QUERY NO: 8 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
8, 'Ms.Sheena', 'Stev', '8/12/2019', '7:00 PM', 'Monday', '9:00 PM', 10, 2.00, 1
);

/* INSERT QUERY NO: 9 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
9, 'Mr.Krish', 'Stev', '8/13/2019', '9:00 AM', 'Tuesday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 10 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
10, 'Mr.Micky', 'Stev', '8/13/2019', '11:00 AM', 'Tuesday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 11 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
11, 'Mr.John Stev', 'Stev', '8/14/2019', '11:00 AM', 'Wednesday', '1:00 PM', 2, 2.00, 4
);

/* INSERT QUERY NO: 12 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
12, 'Mr.Stev Job', 'John', '8/14/2019', '11:00 AM', 'Wednesday', '1:00 PM', 3, 2.00, 3
);

/* INSERT QUERY NO: 13 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
13, 'Mr.Bill Gate', 'John', '8/14/2019', '9:00 AM', 'Wednesday', '11:00 AM', 4, 2.00, 3
);

/* INSERT QUERY NO: 14 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
14, 'Mr.Krish', 'Stev', '8/14/2019', '9:00 AM', 'Wednesday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 15 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
15, 'Mr.Chisty', 'Stev', '8/14/2019', '5:00 PM', 'Wednesday', '7:00 PM', 6, 2.00, 3
);

/* INSERT QUERY NO: 16 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
16, 'Mr.Vicky', 'John', '8/14/2019', '7:00 PM', 'Wednesday', '9:00 PM', 7, 2.00, 1
);

/* INSERT QUERY NO: 17 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
17, 'Mr.Micky', 'Stev', '8/14/2019', '11:00 AM', 'Wednesday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 18 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
18, 'Ms.Victorya', 'John', '8/14/2019', '5:00 PM', 'Wednesday', '7:00 PM', 9, 2.00, 3
);

/* INSERT QUERY NO: 19 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
19, 'Ms.Sheena', 'Stev', '8/14/2019', '7:00 PM', 'Wednesday', '9:00 PM', 10, 2.00, 1
);

/* INSERT QUERY NO: 20 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
20, 'Mr.Krish', 'Stev', '8/15/2019', '9:00 AM', 'Thursday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 21 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
21, 'Mr.Micky', 'Stev', '8/15/2019', '11:00 AM', 'Thursday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 22 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
22, 'Mr.John Stev', 'Stev', '8/17/2019', '11:00 AM', 'Saturday', '1:00 PM', 2, 2.00, 4
);

/* INSERT QUERY NO: 23 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
23, 'Mr.Krish', 'Stev', '8/17/2019', '9:00 AM', 'Saturday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 24 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
24, 'Mr.Micky', 'Stev', '8/17/2019', '11:00 AM', 'Saturday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 25 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
25, 'Mr.John Stev', 'Stev', '8/18/2019', '11:00 AM', 'Sunday', '1:00 PM', 2, 2.00, 4
);

/* INSERT QUERY NO: 26 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
26, 'Mr.Stev Job', 'John', '8/18/2019', '11:00 AM', 'Sunday', '1:00 PM', 3, 2.00, 3
);

/* INSERT QUERY NO: 27 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
27, 'Mr.Bill Gate', 'John', '8/18/2019', '9:00 AM', 'Sunday', '11:00 AM', 4, 2.00, 3
);

/* INSERT QUERY NO: 28 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
28, 'Mr.Krish', 'Stev', '8/18/2019', '9:00 AM', 'Sunday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 29 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
29, 'Mr.Chisty', 'Stev', '8/18/2019', '5:00 PM', 'Sunday', '7:00 PM', 6, 2.00, 3
);

/* INSERT QUERY NO: 30 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
30, 'Mr.Micky', 'Stev', '8/18/2019', '11:00 AM', 'Sunday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 31 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
31, 'Ms.Victorya', 'John', '8/18/2019', '5:00 PM', 'Sunday', '7:00 PM', 9, 2.00, 3
);

/* INSERT QUERY NO: 32 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
32, 'Ms.Eva', 'John', '8/19/2019', '9:00 AM', 'Monday', '1:00 PM', 1, 4.00, 1
);

/* INSERT QUERY NO: 33 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
33, 'Mr.John Stev', 'Stev', '8/19/2019', '11:00 AM', 'Monday', '1:00 PM', 2, 2.00, 4
);

/* INSERT QUERY NO: 34 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
34, 'Mr.Stev Job', 'John', '8/19/2019', '11:00 AM', 'Monday', '1:00 PM', 3, 2.00, 3
);

/* INSERT QUERY NO: 35 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
35, 'Mr.Bill Gate', 'John', '8/19/2019', '9:00 AM', 'Monday', '11:00 AM', 4, 2.00, 3
);

/* INSERT QUERY NO: 36 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
36, 'Mr.Krish', 'Stev', '8/19/2019', '9:00 AM', 'Monday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 37 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
37, 'Mr.Chisty', 'Stev', '8/19/2019', '5:00 PM', 'Monday', '7:00 PM', 6, 2.00, 3
);

/* INSERT QUERY NO: 38 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
38, 'Mr.Micky', 'Stev', '8/19/2019', '11:00 AM', 'Monday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 39 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
39, 'Ms.Victorya', 'John', '8/19/2019', '5:00 PM', 'Monday', '7:00 PM', 9, 2.00, 3
);

/* INSERT QUERY NO: 40 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
40, 'Ms.Sheena', 'Stev', '8/19/2019', '7:00 PM', 'Monday', '9:00 PM', 10, 2.00, 1
);

/* INSERT QUERY NO: 41 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
41, 'Mr.John Stev', 'Stev', '8/20/2019', '11:00 AM', 'Tuesday', '1:00 PM', 2, 2.00, 4
);

/* INSERT QUERY NO: 42 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
42, 'Mr.Krish', 'Stev', '8/20/2019', '9:00 AM', 'Tuesday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 43 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
43, 'Mr.Micky', 'Stev', '8/20/2019', '11:00 AM', 'Tuesday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 44 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
44, 'Mr.John Stev', 'Stev', '8/21/2019', '11:00 AM', 'Wednesday', '1:00 PM', 2, 2.00, 4
);

/* INSERT QUERY NO: 45 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
45, 'Mr.Stev Job', 'John', '8/21/2019', '11:00 AM', 'Wednesday', '1:00 PM', 3, 2.00, 3
);

/* INSERT QUERY NO: 46 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
46, 'Mr.Bill Gate', 'John', '8/21/2019', '9:00 AM', 'Wednesday', '11:00 AM', 4, 2.00, 3
);

/* INSERT QUERY NO: 47 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
47, 'Mr.Krish', 'Stev', '8/21/2019', '9:00 AM', 'Wednesday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 48 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
48, 'Mr.Chisty', 'Stev', '8/21/2019', '5:00 PM', 'Wednesday', '7:00 PM', 6, 2.00, 3
);

/* INSERT QUERY NO: 49 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
49, 'Mr.Vicky', 'John', '8/21/2019', '7:00 PM', 'Wednesday', '9:00 PM', 7, 2.00, 1
);

/* INSERT QUERY NO: 50 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
50, 'Mr.Micky', 'Stev', '8/21/2019', '11:00 AM', 'Wednesday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 51 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
51, 'Ms.Victorya', 'John', '8/21/2019', '5:00 PM', 'Wednesday', '7:00 PM', 9, 2.00, 3
);

/* INSERT QUERY NO: 52 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
52, 'Ms.Sheena', 'Stev', '8/21/2019', '7:00 PM', 'Wednesday', '9:00 PM', 10, 2.00, 1
);

/* INSERT QUERY NO: 53 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
53, 'Mr.Krish', 'Stev', '8/22/2019', '9:00 AM', 'Thursday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 54 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
54, 'Mr.Micky', 'Stev', '8/22/2019', '11:00 AM', 'Thursday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 55 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
55, 'Mr.John Stev', 'Stev', '8/24/2019', '11:00 AM', 'Saturday', '1:00 PM', 2, 2.00, 4
);

/* INSERT QUERY NO: 56 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
56, 'Mr.Krish', 'Stev', '8/24/2019', '9:00 AM', 'Saturday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 57 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
57, 'Mr.Micky', 'Stev', '8/24/2019', '11:00 AM', 'Saturday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 58 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
58, 'Mr.John Stev', 'Stev', '8/25/2019', '11:00 AM', 'Sunday', '1:00 PM', 2, 2.00, 4
);

/* INSERT QUERY NO: 59 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
59, 'Mr.Stev Job', 'John', '8/25/2019', '11:00 AM', 'Sunday', '1:00 PM', 3, 2.00, 3
);

/* INSERT QUERY NO: 60 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
60, 'Mr.Bill Gate', 'John', '8/25/2019', '9:00 AM', 'Sunday', '11:00 AM', 4, 2.00, 3
);

/* INSERT QUERY NO: 61 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
61, 'Mr.Krish', 'Stev', '8/25/2019', '9:00 AM', 'Sunday', '11:00 AM', 5, 2.00, 6
);

/* INSERT QUERY NO: 62 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
62, 'Mr.Chisty', 'Stev', '8/25/2019', '5:00 PM', 'Sunday', '7:00 PM', 6, 2.00, 3
);

/* INSERT QUERY NO: 63 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
63, 'Mr.Micky', 'Stev', '8/25/2019', '11:00 AM', 'Sunday', '1:00 PM', 8, 2.00, 6
);

/* INSERT QUERY NO: 64 */
INSERT INTO table_name(IDNo, StudentName, TrainnerName, Date, InTime, Weekday, OutTime, StudListId, Hours, DAYS)
VALUES
(
64, 'Ms.Victorya', 'John', '8/25/2019', '5:00 PM', 'Sunday', '7:00 PM', 9, 2.00, 3
);

Table 2

* Table 2 *
CREATE TABLE [dbo].[tsStudenList](
    [IdNo] [int] IDENTITY(1,1) NOT NULL,
    [StudentName] [varchar](300) NULL,
    [TrainnerName] [varchar](300) NULL,
    [StudentRegNo] [varchar](15) NULL,
    [Course] [varchar](max) NULL,
    [Duration] [smallint] NULL,
    [Schedule] [varchar](100) NULL,
    [Days] [int] NULL,
    [StartDate]  AS (CONVERT(September 19, 2019,getdate())),
    [Timing] [varchar](100) NULL,
 CONSTRAINT [PK_tsStudenList] PRIMARY KEY CLUSTERED 
(
    [IdNo] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[tsStudAttandance]  WITH CHECK ADD  CONSTRAINT [FK_tsStudAttandance_tsStudenList] FOREIGN KEY([StudListId])
REFERENCES [dbo].[tsStudenList] ([IdNo])
GO
ALTER TABLE [dbo].[tsStudAttandance] CHECK CONSTRAINT [FK_tsStudAttandance_tsStudenList]
GO


     /* INSERT QUERY NO: 1 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
1, 'Ms.Eva', 'John', 'TSSR1900001', 'CCNA', 60, 'SAT', 1, '8/12/2019', '09:00 AM - 01:00 PM'
);

/* INSERT QUERY NO: 2 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
2, 'Mr.John Stev', 'Stev', 'TSSR1900002', 'CCNA', 60, 'SAT-WED', 4, '8/12/2019', '09:00 AM - 01:00 PM'
);

/* INSERT QUERY NO: 3 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
3, 'Mr.Stev Job', 'John', 'TSSR1900003', 'CCNP', 70, 'SUN-MON-WED', 3, '8/12/2019', '09:00 AM - 11 :00 AM'
);

/* INSERT QUERY NO: 4 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
4, 'Mr.Bill Gate', 'John', 'TSSR1900004', 'PHOTOSHOP', 20, 'SUN-MON-WED', 3, '8/12/2019', '09:00 AM - 11:00 AM'
);

/* INSERT QUERY NO: 5 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
5, 'Mr.Krish', 'Stev', 'TSSR1900005', 'INDESIGN', 24, 'SAT-THR', 6, '8/12/2019', '09:00 AM - 01:00 PM'
);

/* INSERT QUERY NO: 6 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
6, 'Mr.Chisty', 'Stev', 'TSSR1900006', 'CEH', 80, 'SUN-MON-WED', 3, '8/12/2019', '11:00 AM - 01:00 PM'
);

/* INSERT QUERY NO: 7 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
7, 'Mr.Vicky', 'John', 'TSSR1900007', 'CEH', 80, 'WED', 1, '8/12/2019', '05:00 PM - 07:00 PM'
);

/* INSERT QUERY NO: 8 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
8, 'Mr.Micky', 'Stev', 'TSSR1900008', 'INDESIGN', 24, 'SAT-THR', 6, '8/12/2019', '09:00 AM - 01:00 PM'
);

/* INSERT QUERY NO: 9 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
9, 'Ms.Victorya', 'John', 'TSSR1900009', 'PHOTOSHOP', 24, 'SUN-MON-WED', 3, '8/12/2019', '09:00 AM - 11:00 PM'
);

/* INSERT QUERY NO: 10 */
INSERT INTO table_name(idno, studentname, trainnername, studentregno, course, duration, schedule, days, startdate, timing)
VALUES
(
10, 'Ms.Sheena', 'Stev', 'TSSR1900010', 'CEH', 40, 'MON & WED', 2, '8/12/2019', '07:00 PM - 09:00 PM'
);

Need a Final Report like this
enter image description here

Here is the Remark should come to YES or No by comparing they Intime and OutTime (By checking the Schedule if SAT-MON-WED means three days, so if the hours are less then 6 Remark Should ‘NO’. Like That Should Check Schedule and Time for Remarks) and Percentage of class status Should sum the hours of this week(Sat-Thu) and divide by Duration of the second table. I got That result Week But I need overall status too if I use Where Clauses Between ‘Start Date’ And ‘End Date’.

Here the sample report for YES ON and Discontinued(more than one month is optional)
enter image description here
This possibility should be when a student does not attend the class for one month Discontinued and in 6days class attended less than or equal to 3 No

Most Important Overall Status and Current week Status as the above pic

Here is the Code Which I tried

  BEGIN
SELECT tsStudAttandance.StudentName as 'Name', tsStudenList.StartDate as 'Start Date',
CASE WHEN
         sum(
                    case 
                        when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                        then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                    else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                    end 
            - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float)) = CAST(tsStudenList.Duration as float)
Then (SELECT top 1 tsStudAttandance.Date FROM tsStudAttandance ORDER BY  tsStudAttandance.Date DESC)

END as 'End Date',
cast(cast(round(sum(
                    case 
                        when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                        then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                    else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                    end 
- cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float))
/ cast(tsStudenList.Duration as float)*100,2) AS DECIMAL(18,2)) as varchar(100)) + ' %' as 'Class Status in %',
(
cast(cast(round(sum(
                    case 
                        when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                        then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                    else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                    end 
- cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float))
/ cast(tsStudenList.Duration as float)*100,2) AS DECIMAL(18,2)) as varchar(100)) + ' %'  ) as 'Over Class Status in %', 
tsStudenList.Course as 'Course Name', tsStudenList.Timing, tsStudenList.Schedule

FROM tsStudAttandance INNER JOIN dbo.tsStudenList ON tsStudAttandance.StudListId = tsStudenList.IdNo 
GROUP BY tsStudAttandance.StudentName,tsStudenList.Duration, tsStudenList.StartDate, tsStudenList.Schedule, tsStudenList.Course, tsStudenList.Timing, tsStudenList.Schedule 

End;

2

Answers


  1. Chosen as BEST ANSWER

    Here the Code for the above Question

    Use modeldb
     Go   
     BEGIN
        Select a.[SNo],a.Name, a.[StartDate],b.[EndDate], a.[WeekStatus], b.[OverAllStatus],a.[CourseName], a.Timing, a.Schedule, a.Regular FROM
        (SELECT 
        ROW_NUMBER() OVER(ORDER BY tsStudAttandance.StudentName ASC) as 'SNo',
    
    tsStudAttandance.StudentName as 'Name', tsStudenList.StartDate as 'StartDate',tsStudenList.StudentRegNo as 'RegNo',
    
    cast(cast(round(sum(
                        case 
                            when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                            then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                        else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                        end 
    - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float))
    / cast(tsStudenList.Duration as float)*100,2) AS DECIMAL(18,2)) as varchar(100)) + ' %' as 'WeekStatus', 
    tsStudenList.Course as 'CourseName', tsStudenList.Timing, tsStudenList.Schedule,
    
    (Case 
            When tsStudenList.InDays = 6    
                AND ((sum(case 
                            when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                            then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                            else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                            end 
                            - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float)))/2)>=3
    
                Then 
                    'YES'
            When tsStudenList.InDays = 5 
                AND ((sum(case 
                            when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                            then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                            else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                            end 
                            - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float)))/2)>=2
                Then 
                    'YES'
            When tsStudenList.InDays = 4 
                AND ((sum(case 
                            when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                            then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                            else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                            end 
                            - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float)))/2)>=1
                Then 
                    'YES'
            When tsStudenList.InDays = 3 
                AND ((sum(case 
                            when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                            then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                            else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                            end 
                            - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float)))/2)>=1
                Then 
                    'YES'
            When tsStudenList.InDays = 2
                AND ((sum(case 
                        when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                        then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                        else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                        end 
                        - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float)))/2)>=1
            Then 
                'YES'
            When tsStudenList.InDays = 1
                AND ((sum(case 
                            when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                            then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                            else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                            end 
                            - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float)))/2)>=1
                Then 
                    'YES'
    
            ELSE
                 'No'
            End)
                    As 'Regular'
    
    FROM tsStudAttandance INNER JOIN dbo.tsStudenList ON tsStudAttandance.StudListId = tsStudenList.IdNo Where tsStudAttandance.Date Between '2019-08-12' AND '2019-08-17' GROUP BY tsStudAttandance.StudentName,tsStudenList.Duration, tsStudenList.StartDate, tsStudenList.Schedule, tsStudenList.Course, tsStudenList.Timing, tsStudenList.Schedule, tsStudenList.InDays,tsStudenList.StudentRegNo) a
    Left join (SELECT tsStudAttandance.StudentName as 'Name' ,
    CASE WHEN
             sum(
    case 
        when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
        then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
    else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime ,2)))as float)
    end 
    - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime,2)))as float)) = CAST(tsStudenList.Duration as float)
    Then (SELECT top 1 tsStudAttandance.Date FROM tsStudAttandance ORDER BY  tsStudAttandance.Date DESC)
    
    END as 'EndDate',
    (cast(cast(round(sum(
                        case 
                            when CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.OutTime , 2))) = 'PM' AND CONVERT(VARCHAR(6), TRIM(' ' FROM Right(tsStudAttandance.InTime , 2))) ='AM'
                            then  cast(CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float)+12 
                        else cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) 
                        end 
    - cast(CONVERT(VARCHAR(6), TRIM(':00 AM' FROM LEFT(tsStudAttandance.Intime , 2)) ) as float))
    / cast(tsStudenList.Duration as float)*100,2) AS DECIMAL(18,2)) as varchar(100)) + ' %'  ) as 'OverAllStatus' 
    From tsStudAttandance INNER JOIN dbo.tsStudenList ON tsStudAttandance.StudListId = tsStudenList.IdNo  Group by tsStudAttandance.StudentName,tsStudenList.Duration) b  on a.Name = b.Name 
    END;
    

    The above Question records limited to two weeks so if for Month and more then a month We can adjust Case for Discontinued in Regular Remark Part.


  2. Answer 1 is Case to Create Stored Procedure Run Good In SQL, Instead of

    CONVERT We can USE SUBSTRING

    CONVERT(VARCHAR(6), TRIM(':00 PM' FROM LEFT(tsStudAttandance.OutTime , 2)) ) as float) Can be Changed to SUBSTRING(tsStudAttandance.OutTime,1,2) and By Using SUBSTRING O9 Will Be Consider as 9 SO we Can USE Replace() and LEN()
    Here is the code that

    BEGIN
    Select a.Name, a.[StartDate],b.[EndDate], a.[WeekStatus], b.[OverAllStatus],a.[CourseName], a.Timing, a.Schedule, a.Regular FROM
    (SELECT 
    
    
    tsStudAttandance.StudentName as 'Name', tsStudenList.StartDate as 'StartDate',tsStudenList.StudentRegNo as 'RegNo',
    
    cast(cast(round(sum(
                        case 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='AM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)+12 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='PM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                            else 
                            cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                        end
                    - cast(REPLACE(SUBSTRING(tsStudAttandance.InTime,1,2),':','') as int)
                        )
    / cast(tsStudenList.Duration as float)*100,2) AS DECIMAL(18,2)) as varchar(100)) + ' %' as 'WeekStatus', 
    tsStudenList.Course as 'CourseName', tsStudenList.Timing, tsStudenList.Schedule,
    
    (Case 
            When tsStudenList.InDays = 6    
                AND ((sum(case 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='AM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)+12 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='PM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                            else 
                            cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                           end
                            - cast(REPLACE(SUBSTRING(tsStudAttandance.InTime,1,2),':','') as int)))/2)>=3
    
                Then 
                    'YES'
            When tsStudenList.InDays = 5 
                AND ((sum(case 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='AM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)+12 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='PM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                            else 
                            cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                           end
                            - cast(REPLACE(SUBSTRING(tsStudAttandance.InTime,1,2),':','') as int)))/2)>=2
                Then 
                    'YES'
            When tsStudenList.InDays = 4 
                AND ((sum(case 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='AM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)+12 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='PM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                            else 
                            cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                           end
                            - cast(REPLACE(SUBSTRING(tsStudAttandance.InTime,1,2),':','') as int)))/2)>=1
                Then 
                    'YES'
            When tsStudenList.InDays = 3 
                AND ((sum(case 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='AM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)+12 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='PM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                            else 
                            cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                           end
                            - cast(REPLACE(SUBSTRING(tsStudAttandance.InTime,1,2),':','') as int)))/2)>=1
                Then 
                    'YES'
            When tsStudenList.InDays = 2
                AND ((sum(case 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='AM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)+12 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='PM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                            else 
                            cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                           end
                            - cast(REPLACE(SUBSTRING(tsStudAttandance.InTime,1,2),':','') as int)))/2)>=1
            Then 
                'YES'
            When tsStudenList.InDays = 1
                AND ((sum(case 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='AM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)+12 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='PM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                            else 
                            cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                           end
                            - cast(REPLACE(SUBSTRING(tsStudAttandance.InTime,1,2),':','') as int)))/2)>=1
                Then 
                    'YES'
    
            ELSE
                 'No'
            End)
                    As 'Regular'
    
    FROM tsStudAttandance INNER JOIN dbo.tsStudenList ON tsStudAttandance.StudListId = tsStudenList.IdNo Where tsStudAttandance.Date Between '2019-08-12' AND '2019-08-17' GROUP BY tsStudAttandance.StudentName,tsStudenList.Duration, tsStudenList.StartDate, tsStudenList.Schedule, tsStudenList.Course, tsStudenList.Timing, tsStudenList.Schedule, tsStudenList.InDays,tsStudenList.StudentRegNo) a
    Left join (SELECT tsStudAttandance.StudentName as 'Name' ,
    CASE WHEN
             sum(case 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='AM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)+12 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='PM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                            else 
                            cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                           end
                            - cast(REPLACE(SUBSTRING(tsStudAttandance.InTime,1,2),':','') as int)) = CAST(tsStudenList.Duration as Int)
    Then (SELECT top 1 tsStudAttandance.Date FROM tsStudAttandance ORDER BY  tsStudAttandance.Date DESC)
    
    END as 'EndDate',
    (cast(cast(round(sum(
                        (case 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='AM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)+12 
                            when SUBSTRING(tsStudAttandance.OutTime,len(RTRIM(tsStudAttandance.OutTime))-1,len(RTRIM(tsStudAttandance.OutTime))) = 'PM' AND SUBSTRING(tsStudAttandance.InTime,len(RTRIM(tsStudAttandance.InTime))-1,len(RTRIM(tsStudAttandance.InTime))) ='PM'
                            then cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                            else 
                            cast(REPLACE(SUBSTRING(tsStudAttandance.OutTime,1,2),':','') as int)
                           end
                            - cast(REPLACE(SUBSTRING(tsStudAttandance.InTime,1,2),':','') as int)))
    / cast(tsStudenList.Duration as float)*100,2) AS DECIMAL(18,2)) as varchar(100)) + ' %'  ) as 'OverAllStatus' 
    From tsStudAttandance INNER JOIN dbo.tsStudenList ON tsStudAttandance.StudListId = tsStudenList.IdNo  Group by tsStudAttandance.StudentName,tsStudenList.Duration) b  on a.Name = b.Name 
    End;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search