ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Select last 7 days record from current Date in SQL Server<p>Hi <a class="username" rel="iammann"> iammann</a>,</p> <p>Refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">DECLARE @tblWeekData AS TABLE(ClientId INT IDENTITY, Name VARCHAR(20), Country VARCHAR(20), Amount INT, Last_Modified_Date DATETIME) INSERT INTO @tblWeekData VALUES(&#39;Mudassar Khan&#39;,&#39;India&#39;,100,&#39;2019-07-05&#39;) INSERT INTO @tblWeekData VALUES(&#39;John Hammond&#39;,&#39;United States&#39;,100,&#39;2019-07-06&#39;) INSERT INTO @tblWeekData VALUES(&#39;Suzanne Mathews&#39;,&#39;France&#39;,100,&#39;2019-07-07&#39;) INSERT INTO @tblWeekData VALUES(&#39;Mudassar Khan&#39;,&#39;India&#39;,100,&#39;2019-07-08&#39;) INSERT INTO @tblWeekData VALUES(&#39;Suzanne Mathews&#39;,&#39;France&#39;,100,&#39;2019-07-09&#39;) INSERT INTO @tblWeekData VALUES(&#39;Mudassar Khan&#39;,&#39;India&#39;,100,&#39;2019-07-10&#39;) INSERT INTO @tblWeekData VALUES(&#39;Mudassar Khan&#39;,&#39;India&#39;,100,&#39;2019-07-11&#39;) INSERT INTO @tblWeekData VALUES(&#39;Suzanne Mathews&#39;,&#39;France&#39;,100,&#39;2019-07-12&#39;) INSERT INTO @tblWeekData VALUES(&#39;John Hammond&#39;,&#39;United States&#39;,100,&#39;2019-07-13&#39;) INSERT INTO @tblWeekData VALUES(&#39;Mudassar Khan&#39;,&#39;India&#39;,100,&#39;2019-07-14&#39;) INSERT INTO @tblWeekData VALUES(&#39;John Hammond&#39;,&#39;United States&#39;,100,&#39;2019-07-15&#39;) INSERT INTO @tblWeekData VALUES(&#39;Mudassar Khan&#39;,&#39;India&#39;,100,&#39;2019-07-16&#39;) INSERT INTO @tblWeekData VALUES(&#39;Mudassar Khan&#39;,&#39;India&#39;,100,&#39;2019-07-17&#39;) INSERT INTO @tblWeekData VALUES(&#39;Mudassar Khan&#39;,&#39;India&#39;,100,&#39;2019-07-18&#39;) DECLARE @CurrentDate DATETIME SET @CurrentDate = &#39;2019/07/12&#39; DECLARE @From DATETIME SET @From = @CurrentDate - 7 DECLARE @To DATETIME SET @To = @CurrentDate - 1 DECLARE @WeekDays VARCHAR(20) SET @WeekDays = (SELECT DATENAME(dw,@CurrentDate)) IF (@WeekDays = &#39;Friday&#39;) SELECT * FROM @tblWeekData WHERE Last_Modified_Date BETWEEN @From AND @To ELSE PRINT &#39;Nothing&#39;</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <table border="1"> <tbody> <tr> <td><strong>ClientId</strong></td> <td><strong>Name</strong></td> <td><strong>Country</strong></td> <td><strong>Amount</strong></td> <td><strong>Last_Modified_Date</strong></td> </tr> <tr> <td>1</td> <td>Mudassar Khan</td> <td>India</td> <td>100</td> <td>7/5/2019 0:00</td> </tr> <tr> <td>2</td> <td>John Hammond</td> <td>United States</td> <td>100</td> <td>7/6/2019 0:00</td> </tr> <tr> <td>3</td> <td>Suzanne Mathews</td> <td>France</td> <td>100</td> <td>7/7/2019 0:00</td> </tr> <tr> <td>4</td> <td>Mudassar Khan</td> <td>India</td> <td>100</td> <td>7/8/2019 0:00</td> </tr> <tr> <td>5</td> <td>Suzanne Mathews</td> <td>France</td> <td>100</td> <td>7/9/2019 0:00</td> </tr> <tr> <td>6</td> <td>Mudassar Khan</td> <td>India</td> <td>100</td> <td>7/10/2019 0:00</td> </tr> <tr> <td>7</td> <td>Mudassar Khan</td> <td>India</td> <td>100</td> <td>7/11/2019 0:00</td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/113350/Select-last-7-days-record-from-current-Date-in-SQL-Server/https://www.aspforums.net:443/Threads/113350/Select-last-7-days-record-from-current-Date-in-SQL-Server/Wed, 17 Jul 2019 02:17:01 GMT