Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Last full week in sql

Avatar of Noreen McHugh
Noreen McHughFlag for Ireland asked on
Microsoft SQL Server 2005Microsoft SQL Server 2008
5 Comments1 Solution750 ViewsLast Modified:
I am having a problem with selecting the last full week , the code below shows every thing after midnight Sunday to before midnight the next Sunday.
 I just want to see from 08.00 Monday morning to 07.00 am the next monday morming.
DECLARE @TodayDayOfWeek INT
DECLARE @EndOfPrevWeek DateTime
DECLARE @StartOfPrevWeek DateTime
SET @TodayDayOfWeek = datepart(dw, GetDate())
SET @EndOfPrevWeek = DATEADD(dd, -@TodayDayOfWeek, GetDate())
SET @StartOfPrevWeek = DATEADD(dd, -(@TodayDayOfWeek+6), GetDate())
SELECT     TOP (100) PERCENT dbo.CreateOrder.n_OrderOriginallyPlacedTime, dbo.Plu.Plu, dbo.Plu.ItemName, dbo.Plu.Price, dbo.t_OrderLines.n_Amount, dbo.t_OrderLines.n_OrderNum, 
                      dbo.t_OrderLines.n_Type, dbo.t_OrderLines.n_MenuId, dbo.t_OrderPayment.n_Order, dbo.t_OrderPayment.n_PayAmount 
FROM         dbo.t_OrderPayment FULL OUTER JOIN
                      dbo.CreateOrder ON dbo.t_OrderPayment.nStoreID = dbo.CreateOrder.nStoreID AND 
                      dbo.t_OrderPayment.n_Order = dbo.CreateOrder.n_OrderNum FULL OUTER JOIN
                      dbo.t_OrderLines ON dbo.CreateOrder.n_OrderNum = dbo.t_OrderLines.n_OrderNum FULL OUTER JOIN
                      dbo.Plu ON dbo.t_OrderLines.n_MenuId = dbo.Plu.n_MenuId
WHERE     (dbo.t_OrderLines.nStoreID = '528') AND (dbo.CreateOrder.nStoreID = '528') AND (dbo.CreateOrder.n_StatusFlags <> '6') AND 
                      (dbo.t_OrderLines.n_Type <> '26') AND (dbo.t_OrderLines.n_Type <> '18') AND(dbo.CreateOrder.n_OrderOriginallyPlacedTime BETWEEN 
CONVERT(VARCHAR, @StartOfPrevWeek,7)
AND
CONVERT(VARCHAR, @EndOfPrevWeek+1,7))
 AND (dbo.t_OrderLines.n_MenuId <> '2719')
ORDER BY dbo.CreateOrder.n_OrderOriginallyPlacedTime
DECLARE @TodayDayOfWeek INT
DECLARE @EndOfPrevWeek DateTime
DECLARE @StartOfPrevWeek DateTime
SET @TodayDayOfWeek = datepart(dw, GetDate())
SET @EndOfPrevWeek = DATEADD(dd, -@TodayDayOfWeek, GetDate())
SET @StartOfPrevWeek = DATEADD(dd, -(@TodayDayOfWeek+6), GetDate())
SELECT     TOP (100) PERCENT dbo.CreateOrder.n_OrderOriginallyPlacedTime, dbo.Plu.Plu, dbo.Plu.ItemName, dbo.Plu.Price, dbo.t_OrderLines.n_Amount, dbo.t_OrderLines.n_OrderNum, 
                      dbo.t_OrderLines.n_Type, dbo.t_OrderLines.n_MenuId, dbo.t_OrderPayment.n_Order, dbo.t_OrderPayment.n_PayAmount 
FROM         dbo.t_OrderPayment FULL OUTER JOIN
                      dbo.CreateOrder ON dbo.t_OrderPayment.nStoreID = dbo.CreateOrder.nStoreID AND 
                      dbo.t_OrderPayment.n_Order = dbo.CreateOrder.n_OrderNum FULL OUTER JOIN
                      dbo.t_OrderLines ON dbo.CreateOrder.n_OrderNum = dbo.t_OrderLines.n_OrderNum FULL OUTER JOIN
                      dbo.Plu ON dbo.t_OrderLines.n_MenuId = dbo.Plu.n_MenuId
WHERE     (dbo.t_OrderLines.nStoreID = '528') AND (dbo.CreateOrder.nStoreID = '528') AND (dbo.CreateOrder.n_StatusFlags <> '6') AND 
                      (dbo.t_OrderLines.n_Type <> '26') AND (dbo.t_OrderLines.n_Type <> '18') AND(dbo.CreateOrder.n_OrderOriginallyPlacedTime BETWEEN 
CONVERT(VARCHAR, @StartOfPrevWeek,7)
AND
CONVERT(VARCHAR, @EndOfPrevWeek+1,7))
 AND (dbo.t_OrderLines.n_MenuId <> '2719')
ORDER BY dbo.CreateOrder.n_OrderOriginallyPlacedTime
ASKER CERTIFIED SOLUTION
Avatar of dougaug
dougaugFlag of Brazil image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers