Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Generate Records For gaps To Create A Chart for every Date

$
0
0
I want to generate diagram for score in every day - From Regdate For every User to now(But Users Have only scores in some days)----------------------------------------------------------------------------------------CREATE TABLE [dbo].[TBL_DayScore]( [Id] [int] NULL, [UserId] [int] NULL, [Score] [int] NULL, [DateGetScore] [datetime] NULL) ON [PRIMARY]GOCREATE TABLE [dbo].[Tbl_UserReg]( [Id] [int] NULL, [UserId] [int] NULL, [RegDate] [datetime] NULL) ON [PRIMARY]GOINSERT [TBL_DayScore] ([Id], [UserId], [Score], [DateGetScore]) VALUES (1, 1, 50, CAST(N'2015-02-01 00:00:00.000' AS DateTime))INSERT [TBL_DayScore] ([Id], [UserId], [Score], [DateGetScore]) VALUES (2, 1, 30, CAST(N'2015-02-02 00:00:00.000' AS DateTime))INSERT [TBL_DayScore] ([Id], [UserId], [Score], [DateGetScore]) VALUES (3, 1, -10, CAST(N'2015-02-05 00:00:00.000' AS DateTime))INSERT [TBL_DayScore] ([Id], [UserId], [Score], [DateGetScore]) VALUES (4, 1, 25, CAST(N'2015-02-10 00:00:00.000' AS DateTime))INSERT [TBL_DayScore] ([Id], [UserId], [Score], [DateGetScore]) VALUES (5, 2, 7, CAST(N'2015-02-05 00:00:00.000' AS DateTime))INSERT [TBL_DayScore] ([Id], [UserId], [Score], [DateGetScore]) VALUES (6, 2, 10, CAST(N'2015-02-25 00:00:00.000' AS DateTime))INSERT [TBL_DayScore] ([Id], [UserId], [Score], [DateGetScore]) VALUES (7, 3, 100, CAST(N'2015-02-20 00:00:00.000' AS DateTime))INSERT [Tbl_UserReg] ([Id], [UserId], [RegDate]) VALUES (1, 1, CAST(N'2015-02-01 00:00:00.000' AS DateTime))INSERT [Tbl_UserReg] ([Id], [UserId], [RegDate]) VALUES (2, 2, CAST(N'2015-02-03 00:00:00.000' AS DateTime))INSERT [Tbl_UserReg] ([Id], [UserId], [RegDate]) VALUES (3, 3, CAST(N'2015-02-15 00:00:00.000' AS DateTime))-----------------------------------------Result That I Needed : (I want to generate diagram for score in every day - From Regdate to now)(And The other side : I have a table that have All Day Date and can join to these tables)(Example For User1)1 - 2015-02-01 - 501 - 2015-02-02 - 301 - 2015-02-03 - 01 - 2015-02-04 - 01 - 2015-02-05 - -101 - 2015-02-06 - 01 - 2015-02-07 - 01 - 2015-02-08 - 01 - 2015-02-09 - 01 - 2015-02-10 - 251 - 2015-02-11 - 0...1 - 2015-02-25 - 02 - 2015-02-03 - 0 (User 2 must Started in its register date)2 - 2015-02-04 - 0 2 - 2015-02-05 - 7 2 - 2015-02-06 - 0 ....

Viewing all articles
Browse latest Browse all 3145

Trending Articles