sql - How to get the data for the current week from MSSQL -


I wanted to know how I can get records of the current week.

The query I am using is:

  DECLARE @TableX TABLE ([Date] DATETIME) Include @TableXSelect '2014-2-17 Select 'Union All' 2014-2-18 'Union All Substitutes' 2014-2-19' Union All Selection '2014-2-20' Union All Substitutes' 2014-2-21 'Select * SettleABADADATTIFF = DateDD (Day, DATEDIFF (DAY, 0, GETDATE ()) / 7 * 7, 0) and date & lt; = DATEADD (DAY, DATEDIFF (DAY, -1, GETDATE ()), 0)   

The query I wrote does not generate data correctly? Can anyone please tell me what is wrong in the query?

The following are the records I received from this query:

  2014-02-17 00: 00: 00.000 2014- 02-18 00: 00: 00.000    

Please try to use CTE. According to the question given below, 7 days a week is considered 7 days a week.

 ; With t as (Select Date (wk, dethiff (wk, 0, getdate ()), -1) AS Weekday, 1 cnt unions all select week + 1, cnt + 1 to t WHERE cnt + 1 & lt; 8 ) Choose convert (NVHAR (20), day of week, 106) FTT by name, weekend, datannum (doo, wy)    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -