I've below Stored Procedure
named GetFilteredArticles
which returns 7 seperate tables
for each day of a week
i.e. Monday to Sunday
CREATE Procedure [dbo].[GetFilteredArticles]
@UserName NVARCHAR(100),
AS
BEGIN
SET NOCOUNT ON;
[**Returns table for Monday**]
SELECT PostID,Title,convert(char(10),PostDate,101) as PostDate,IsEntertainment, ISNULL(DrPick ,0) as DrPick,
ImageURL,ISNULL(MustPick ,0) as MustPick ,ISNULL(Lead ,0) as Lead
,ISNULL(NonLead,0) as NonLead , convert(char(10),CreationDate,101) as CreationDate,ISNULL(TBW,0) as TBW,
SortOrder,NLDate,[Day], PostURL, Direction,ISNULL(IsArticleLevelPost,0) as IsArticleLevelPost ,Sources, HeadLine,
ISNULL(PromoteTo,0) as PromoteTo,ParentID, PostLevel, IsHLTestPassed, Synapsis, ProjectedViews,ISNULL([SaveChecked],0) as [SaveChecked]
FROM PromoteToArticleNLPrep
where day='Monday' and UserName = @UserName <--Condition [where day='Monday']
order by ISNULL(SortOrder,0) asc
[**Returns table for Tuesday**]
SELECT PostID,Title,convert(char(10),PostDate,101) as PostDate,IsEntertainment, ISNULL(DrPick ,0) as DrPick,
ImageURL,ISNULL(MustPick ,0) as MustPick ,ISNULL(Lead ,0) as Lead
,ISNULL(NonLead,0) as NonLead , convert(char(10),CreationDate,101) as CreationDate,ISNULL(TBW,0) as TBW,
SortOrder,NLDate,[Day], PostURL, Direction , ISNULL(IsArticleLevelPost,0) as IsArticleLevelPost,Sources, HeadLine ,
ISNULL(PromoteTo,0) as PromoteTo,ParentID, PostLevel, IsHLTestPassed, Synapsis, ProjectedViews,ISNULL([SaveChecked],0) as [SaveChecked]
FROM PromoteToArticleNLPrep
where day='Tuesday' and UserName = @UserName <--Condition [where day='Tuesday']
order by ISNULL(SortOrder,0) asc
[**Returns table for Wednesday**]
SELECT PostID,Title,convert(char(10),PostDate,101) as PostDate,IsEntertainment, ISNULL(DrPick ,0) as DrPick,
ImageURL,ISNULL(MustPick ,0) as MustPick ,ISNULL(Lead ,0) as Lead
,ISNULL(NonLead,0) as NonLead , convert(char(10),CreationDate,101) as CreationDate,ISNULL(TBW,0) as TBW,
SortOrder,NLDate,[Day], PostURL, Direction , ISNULL(IsArticleLevelPost,0) as IsArticleLevelPost,Sources, HeadLine ,
ISNULL(PromoteTo,0) as PromoteTo,ParentID, PostLevel, IsHLTestPassed, Synapsis, ProjectedViews,ISNULL([SaveChecked],0) as [SaveChecked]
FROM PromoteToArticleNLPrep
where day='Wednesday' and UserName = @UserName <--Condition [where day='Wednesday']
order by ISNULL(SortOrder,0) asc
.....
.....
.....
..... and so on for rest of the days...
END
Note - day is a column name
So, in all, there will be 7 tables
returning for each day.
For this i would like to use SELECT Query
at the minimal level, how should i do that..
Also I have 2
below options to remove redundancy
-
- Use
While loop
7 times whereday will be dyanamic
Static SQL Query N'
' only day will be dyanmic
Expected- A single Select query
which will return 7 tables
for each day
, instead
of using 7
different select statements
.
Any other suggestions or thoughts
on this..?