﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server Newbies  / Date Range or last 6 months of data / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 20:47:56 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Date Range or last 6 months of data</title><link>http://www.sqlservercentral.com/Forums/Topic1402022-1292-1.aspx</link><description>[quote][b]HOG (1/2/2013)[/b][hr]Is it possible to run a query that uses a date range, but if the records do not have any data, to then go back six months before the start date?[/quote] Whats the requirement for this? if you talk about query readability or simplicity then date/time range hardly would make any difference. and if we talk about performance perspective then  1) it will search for say current 6 month if data is not there 2) search for last 6 month. what i think here is , either you mention  complete range (1+ 2)  OR any logic which will first check in current 6 then last 6. in both cases resource consumption will be same (BUt if there is partioning setup then  there will be boost in search process when  data is lying on different disks )</description><pubDate>Thu, 03 Jan 2013 04:28:59 GMT</pubDate><dc:creator>Bhuvnesh</dc:creator></item><item><title>RE: Date Range or last 6 months of data</title><link>http://www.sqlservercentral.com/Forums/Topic1402022-1292-1.aspx</link><description>[quote][b]opc.three (1/2/2013)[/b][hr]Your request could be taken multiple ways, I think. If you have a moment to spare please post a table definition (CREATE TABLE statement), some sample data (INSERT statements), your expected results per that sample data and what you have tried so far and I will be happy to help you find a query that will return the rows you need.[/quote]Dear HOGyou have given us your query...great and thanks,,,,but we cant see what you can see.I am sure that this can be resolved for you....but it will be much easier for us to help you if you can do as OPC suggested above .....that is please  :     provide create table statements for your three tables that you refer to     provide some sample data as insert statements to populate these tables     and based on the sample data...what results (and the reason why) you are expecting.kind regards</description><pubDate>Wed, 02 Jan 2013 14:30:21 GMT</pubDate><dc:creator>J Livingston SQL</dc:creator></item><item><title>RE: Date Range or last 6 months of data</title><link>http://www.sqlservercentral.com/Forums/Topic1402022-1292-1.aspx</link><description>Thanks for the reply!Here is what I have been working with today.DECLARE @StartDate DATETIME = NULL,@EndDate DATETIME = NULLSET @StartDate = '2011-08-01'SET @EndDate = '2011-08-31'SELECT  pnl.monthdate,customer.custCode ,cust.Revenue ,pnl.NetRevenue,pnl.NetRevenue - cust.plannedRevenue AS Diff,getYtd(pnl.familycode, pnl.monthDate) AS YtdFROM Customer  LEFT OUTER JOIN pnl    ON customer.Code = pnl.code AND (pnl.monthdate &amp;gt;= @StartDate AND pnl.monthdate &amp;lt;= @EndDate)					  LEFT OUTER JOIN MonCustomer AS Cust   ON customer.Code = cust.code AND pnl.monthdate = cust.MonthDateWHERE customer.custCode IN (SELECT DISTINCT custcode FROM pnl WHERE YEAR(DATEADD(YEAR,-1,pnl)) &amp;lt; CAST(YEAR(@StartDate) AS NVARCHAR(20)))This what I am getting so far.Monthdate     Customer    Revenue      NetRev         Diff                   Ytd2011-08-01   Customer1   140000.00   138000.00	-2000                957000.00NULL            Customer2   0                0                 0                      0For Customer2, if I change the date range to 03-01-2011 to 03-31-2011 I will get some data for that customer. I would like to see Customer2 because they had revenue in the past 6 months. There WHERE clause at the end we were trying to get it to pull all customers within a year, it does, but still no data for those particular customers.Hope this helps. Thanks!!!</description><pubDate>Wed, 02 Jan 2013 13:56:16 GMT</pubDate><dc:creator>HOG</dc:creator></item><item><title>RE: Date Range or last 6 months of data</title><link>http://www.sqlservercentral.com/Forums/Topic1402022-1292-1.aspx</link><description>Your request could be taken multiple ways, I think. If you have a moment to spare please post a table definition (CREATE TABLE statement), some sample data (INSERT statements), your expected results per that sample data and what you have tried so far and I will be happy to help you find a query that will return the rows you need.</description><pubDate>Wed, 02 Jan 2013 13:20:53 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>Date Range or last 6 months of data</title><link>http://www.sqlservercentral.com/Forums/Topic1402022-1292-1.aspx</link><description>Is it possible to run a query that uses a date range, but if the records do not have any data, to then go back six months before the start date?</description><pubDate>Wed, 02 Jan 2013 12:03:38 GMT</pubDate><dc:creator>HOG</dc:creator></item></channel></rss>