That TSQL statement doesn't in fact work as the "'01' as Datetime" needs to be "'01' as Date" because the day function needs a date as a parameter not a datetime.
Dave C -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of MB Software Solutions, LLC Sent: 10 May 2011 14:01 To: ProFox Email List Subject: Re: [NF] T-SQL Last day of the month On 5/10/2011 8:46 AM, Stephen Russell wrote: > Start is now in the statement and builds up through the iterations of > the date math. > > > SELECT DAY( DATEADD --<< 4. > Extract the last day > ( DAY, -1, --<< 3. Find > last day of current month > DATEADD(MONTH,1, --<< 2. > Find first day of next month > CAST( CAST( --<< 1. > Find first day of the current month > YEAR(CURRENT_TIMESTAMP) AS VARCHAR(04)) > + RIGHT( ('0' + > CAST(MONTH(CURRENT_TIMESTAMP) AS VARCHAR(02))) , 2 ) > + '01' AS DATETIME) > ) > ) > ) > > Oh I'm so glad that that's so clear and easy to understand. LOL -- Mike Babcock, MCP MB Software Solutions, LLC President, Chief Software Architect http://mbsoftwaresolutions.com http://fabmate.com http://twitter.com/mbabcock16 _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/[email protected] ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious. _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/[email protected] ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

