I'm stuck on the following problem.  I have a start range date and end range date calculated by a query and I have three columns also produced by another query, the outcome of the last query is:  PRJ_ID | START_DATE | END_DATE   I want to produce an output using a stored procedure that considering all the months between start range date and end range date produces an output like this:  PRJ_ID | MONTHS1-YEAR | MONTHS2-YEAR | ... | MONTHSN-YEAR XXXX   | YES     | YES     | ... | NO   The yes or no is obtained checking if the current month is in between the start_date and end_date of the project (table obtained above).  I'm able to produce all the months between two dates with this code:  DECLARE @StartDate  DATETIME,         @EndDate    DATETIME;  SELECT   @StartDate = '20110501'                 ,@EndDate   = '20110801';  SELECT       DATENAME(MONTH, DATEADD(MONTH, x.number, @StartDate)) AS MonthName FROM         master.dbo.spt_values x WHERE        x.type = 'P'             AND x.number &lt;= DATEDIFF(MONTH, @StartDate, @EndDate);   But I'm stuck on producing the last result.  Here is my try, but I'm getting an error on @prjdates format that is not datetime:  DECLARE @StartDate  DATETIME,         @EndDate    DATETIME,         @minStart    DATETIME,         @orig_estimated_MaxEnd    DATETIME,         @maxEnd    DATETIME,         @curr_planned_MaxEnd         DATETIME;   SELECT   @StartDate = '20110501'                 ,@EndDate   = '20150801';  SET @minStart = (SELECT MIN(start_date)                  FROM [PPM].[dbo].[prj_details]                  WHERE start_date IS NOT NULL                     AND start_date &lt;&gt; '1900-01-01') ;  SET @orig_estimated_MaxEnd = (SELECT MAX( DATEADD(day,orig_estimated_duration*7, start_date)) As FinishDate                               FROM [PPM].[dbo].[prj_details]                               WHERE start_date IS NOT NULL);  SET @curr_planned_MaxEnd = (SELECT MAX(curr_planned_LF)                             FROM [PPM].[dbo].[status_and_updates]                              WHERE curr_planned_LF IS NOT NULL);  SET @maxEnd = (SELECT                    CASE                        WHEN @orig_estimated_MaxEnd &gt; @curr_planned_MaxEnd                          THEN @orig_estimated_MaxEnd                        ELSE @curr_planned_MaxEnd                     END AS MinValue);                  print @minStart; print @orig_estimated_MaxEnd; print @curr_planned_MaxEnd; print @maxEnd;  DECLARE @prjDates VARCHAR(MAX);  DECLARE @prjDatesTable TABLE (     [prjDate] DATETIME );  DECLARE  @from datetime, @to datetime;  SET @from = '20110501'; SET @to = '20150501';  ;WITH Numbers (Number) AS (     SELECT           row_number() over (order by object_id)     FROM          sys.all_objects) INSERT INTO @prjDatesTable      SELECT          dateadd(month, number, @from) AS months     FROM Numbers     WHERE number &lt;= datediff(month, @from, @to);  SELECT @prjDates = COALESCE(@prjDates + '],[', '') +       (LEFT(CONVERT(VARCHAR, [prjDate], 101),6) + RIGHT(YEAR([prjDate]),2)) FROM @prjDatesTable ORDER BY [prjDate] DESC;  DECLARE @projects TABLE(PRJ_ID varchar(200),  START_DATE DATEtime, END_DATE datetime) INSERT INTO @projects      SELECT p.id,start_date,curr_planned_LF as END_DATE     from [PPM].[dbo].[prj_details]as p     left join [PPM].[dbo].[status_and_updates] as s      on p.id=s.id     where curr_planned_LF is not null      and start_date IS NOT NULL;  --select * from @projects; select * from     @projects pivot (   count(prj_id)   for start_date in  ([' + @prjDates + ']) ) piv;
Let's say I have Table A: BookingsPerPerson  Person_Id    ArrivalDate    DepartureDate 123456       2012-01-01     2012-01-04 213415       2012-01-02     2012-01-07   What I need to achieve with a view is the following:  Person_Id    ArrivalDate    DepartureDate    Jan-01    Jan-02    Jan-03    Jan-04    Jan-05    Jan-06    Jan-07 123456       2012-01-01     2012-01-04       1         1         1         1 213415       2012-01-02     2012-01-07                 1         1         1         1         1         1   The system is for events, so each hotel booking could take anything between 1 to 15 days but no more than that. Any ideas would be very much appreciated.
How do I check that multiple keys are in a dict in a single pass? How can I send a custom desktop notification? I have a custom script and I want to send a desktop notification (the one that appears in the top right corner of the screen) with a custom message. How do I do that? Add leading zeroes to number in Java? A Terms of Service update restricting companies that scrape your profile information without your permission I want to install the latest Python tarball on Ubuntu, downloaded from .  Is this is a correct way to install?  ./configure make make install   If not, how do I do that? Move partition data with dd to the right Write to FIFO only if it exists Fractional Laplacian on the torus Why does no line appear when using Interpolate Line in ArcMap? How to calculate the following sum: How may one calculate  $$\lim_{n\to\infty} \ \left(\left(\sum_{k=1}^{n} \frac{1}{3k-1}\right) - \frac{\ln n}{3}\right) \ ?$$ What is the limit of $\lim\limits_{x→∞}\frac{\sin x}{x}$ What's the best way to take a segment out of a text file? What's a good way of extracting say, lines 20 -45 out of a huge text file. Non-interactively of course! So I've got the shout in my shouts list and I've unlocked all three parts of it, but I can't seem to be able to use it all, just the first part.  Am I missing something? I still have a quest for 'Learn the first word of Durnehviir's shout' but it's showing as me having already got it.  What gives? Just upgraded to Mountain Lion and I have to buy iPhoto again? I stand up and I look at two parallel railroad tracks. I find that converge away from me. Why? Can someone explain me why parallel lines seem to converge, please? I am curious as to why "nay" replaces the simple unequivocal "no" in the context of voting.  My research in Merriam-Webster tells me that "nay" means "no" (not the other way around) and the first known use of "nay" appeared in 1400s. Since the use of "no" existed before 1400 and the word remains to be used afterward, why would "nay" become the preferred choice of word when it comes to voting. Any idea? PDF of product of variables Could anyone please indicate a general strategy (if there is any) to get the PDF (or CDF) of the  product of two random variables, each having known distributions and limits?   My particular need is the following: Let $w :=u \cdot v$. The PDF of $u$ is $$\frac{1}{\pi u}\frac{1}{\sqrt{u^2-0.25}},$$ for $z&gt;0.5$ and the PDF of $v$ is $$\exp\left(-\frac{v}{v_0}\right),$$ for $v_1&lt;v&lt;v_2$. What's the PDF of $w$? Today I was thinking about composition of functions.  It has nice properties, its always associative, there is an identity, and if we restrict to bijective functions then we have an inverse.  But then I thought about commutativity.  My first intuition was that bijective self maps of a space should commute but then I saw some counter-examples. The symmetric group is only abelian if $n \le 2$ so clearly there need to be more restrictions on functions than bijectivity for them to commute.  The only examples I could think of were boring things like multiplying by a constant or maximal tori of groups like $O(n)$ (maybe less boring).  My question: In a euclidean space, what are (edit) some nice characterizations of sets of functions that commute? What about in a more general space?   Bonus: Is this notion of commutativity important anywhere in analysis? Level 10 vim adventures beers on the wall complete solution I saw this question  but it doesn't have a full solution. What is the full solution to the 99 bottles of beer on the wall for Vim adventures?  Context: for the sake of being a good SO member I will give more details but a full solution will answer my question. It seems from reading the other post that my register is incorrect for some reason. I can't get the &lt;NL&gt;. I think that's the issue since pasting won't work... Some sort of battle school (no, not Ender's Game), where teens are being trained as military commanders.   The control system for their army hinges around some sort of system that requires extremely fine motor control -- being able to "push" around digital representations of military units using a special interface that interprets minute finger movements.  The boy protagonist eventually meets a girl in the battle school, and is astonished to learn that most people do not live as well as he does -- for instance, he gets a fresh jumpsuit outfit every day and disposes of the old one; this is a luxury.  One scene I recall is them kissing for a moment in some sort of underground passageway; the boy protagonist notes the exact length of the kiss, as he has been trained to have heightened time perception.  I don't recall much about other commander characters; I think they have different special abilities, and one other major character might have physical deformities, possibly because of postwar-radiation-related birth defects.  They have been training for an upcoming, prearranged final battle between all the existing national governments; the military units are very possibly robotic or entirely digital in nature, so as to avoid wasting materiel / human life.    They ultimately win the battle, just barely; I think the girl protagonist gives them an edge in the competition by hacking the timing / control system in favor of their team, causing a discrepancy which only the boy protagonist notices due to his heightened perceptions.  It was agreed that the winning government gets dominion over one of the few islands of land left that was not irradiated in some previous war; the protagonists get to live there as a reward for their victory.  I believe the boy protagonist later realizes he's gradually losing his ability to exactly quantify the passage of time.  Published no later than 2004, likely somewhere between 1980-2000, probably sometime in the '90s.