<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Query to Find First and Last Day of Current Month</title>
	<atom:link href="http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Onttu</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-57744</link>
		<dc:creator>Onttu</dc:creator>
		<pubDate>Thu, 19 Nov 2009 16:02:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-57744</guid>
		<description>I ran the following code as part of a statement to capture 
something occuring between the first of the current month and the end of the current month however when ever i refrence Stardate or Enddate i get the following error.  Any ideas how to make the columns remain in effect throuhout the entire query?
 
Msg 207, Level 16, State 3, Line 10
Invalid column name &#039;Startdate&#039;.
Msg 207, Level 16, State 3, Line 10
Invalid column name &#039;Enddate&#039;.



declare @mydate datetime
select @mydate = getdate()

SELECT CONVERT(varchar(10),DATEADD(dd,-(DAY(@mydate)-1),@mydate),120) as ‘StartDate’

SELECT CONVERT(varchar(10),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))-1),DATEADD(mm,-1,@mydate)),120) as ‘EndDate’</description>
		<content:encoded><![CDATA[<p>I ran the following code as part of a statement to capture<br />
something occuring between the first of the current month and the end of the current month however when ever i refrence Stardate or Enddate i get the following error.  Any ideas how to make the columns remain in effect throuhout the entire query?</p>
<p>Msg 207, Level 16, State 3, Line 10<br />
Invalid column name &#8216;Startdate&#8217;.<br />
Msg 207, Level 16, State 3, Line 10<br />
Invalid column name &#8216;Enddate&#8217;.</p>
<p>declare @mydate datetime<br />
select @mydate = getdate()</p>
<p>SELECT CONVERT(varchar(10),DATEADD(dd,-(DAY(@mydate)-1),@mydate),120) as ‘StartDate’</p>
<p>SELECT CONVERT(varchar(10),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))-1),DATEADD(mm,-1,@mydate)),120) as ‘EndDate’</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pradeep</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-55615</link>
		<dc:creator>Pradeep</dc:creator>
		<pubDate>Sat, 05 Sep 2009 11:28:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-55615</guid>
		<description>I need to know the concept of Parameterized views?? Is it realted to functions returning table are parameterized views??

How these are different then Stored procedures.??

Please tell me!!</description>
		<content:encoded><![CDATA[<p>I need to know the concept of Parameterized views?? Is it realted to functions returning table are parameterized views??</p>
<p>How these are different then Stored procedures.??</p>
<p>Please tell me!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DEVIKA</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-53627</link>
		<dc:creator>DEVIKA</dc:creator>
		<pubDate>Sat, 11 Jul 2009 08:57:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-53627</guid>
		<description>Hellooo...


M the student of MCA n i hv such a query....

der detail is as follow....

-&gt; PRINT THE INFORMATION OF CUSTOMERS WHO HAVE BEEN BORN IN THE MONTH OF FEBRUARY.</description>
		<content:encoded><![CDATA[<p>Hellooo&#8230;</p>
<p>M the student of MCA n i hv such a query&#8230;.</p>
<p>der detail is as follow&#8230;.</p>
<p>-&gt; PRINT THE INFORMATION OF CUSTOMERS WHO HAVE BEEN BORN IN THE MONTH OF FEBRUARY.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haamidou</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-53524</link>
		<dc:creator>Haamidou</dc:creator>
		<pubDate>Tue, 07 Jul 2009 17:40:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-53524</guid>
		<description>Thanks a lot Imran. I also got how to get the end date as well i.e. December 31st of any given date.</description>
		<content:encoded><![CDATA[<p>Thanks a lot Imran. I also got how to get the end date as well i.e. December 31st of any given date.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-53503</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Tue, 07 Jul 2009 05:08:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-53503</guid>
		<description>Haamidou, 

Try this, 

Select Datename ( dw, Dateadd ( dd , -1 , datename (yy, dateadd (year, +1, getdate()))))

Output : Thursday

Replace Getdate() with your date column name. 

Please test this before using it in your code.

~ IM.</description>
		<content:encoded><![CDATA[<p>Haamidou, </p>
<p>Try this, </p>
<p>Select Datename ( dw, Dateadd ( dd , -1 , datename (yy, dateadd (year, +1, getdate()))))</p>
<p>Output : Thursday</p>
<p>Replace Getdate() with your date column name. </p>
<p>Please test this before using it in your code.</p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haamidou</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-53492</link>
		<dc:creator>Haamidou</dc:creator>
		<pubDate>Mon, 06 Jul 2009 18:47:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-53492</guid>
		<description>I was going through this forum hoping to get the last day of year of a given date but can&#039;t find how to get. Anyone can help me how to get it. I need this badly.

Thanks.</description>
		<content:encoded><![CDATA[<p>I was going through this forum hoping to get the last day of year of a given date but can&#8217;t find how to get. Anyone can help me how to get it. I need this badly.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-52956</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Fri, 12 Jun 2009 03:19:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-52956</guid>
		<description>@Tania.

If you have SQL Server 2005 or higher , you can try this, 

create table #temp(id int identity, ename varchar(10))
go

insert into #temp values (&#039;Testing&#039;)
go 12 -- This should not be replaced.

go 

select datename (mm , dateadd (mm, id - (datepart(mm,getdate())), getdate())) Month_Names
from #temp
go

drop table #temp
go

I am sure, there is a better way of doing this, at-least this should give you a start.

~ IM.</description>
		<content:encoded><![CDATA[<p>@Tania.</p>
<p>If you have SQL Server 2005 or higher , you can try this, </p>
<p>create table #temp(id int identity, ename varchar(10))<br />
go</p>
<p>insert into #temp values (&#8216;Testing&#8217;)<br />
go 12 &#8212; This should not be replaced.</p>
<p>go </p>
<p>select datename (mm , dateadd (mm, id &#8211; (datepart(mm,getdate())), getdate())) Month_Names<br />
from #temp<br />
go</p>
<p>drop table #temp<br />
go</p>
<p>I am sure, there is a better way of doing this, at-least this should give you a start.</p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tania</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-52940</link>
		<dc:creator>Tania</dc:creator>
		<pubDate>Thu, 11 Jun 2009 12:18:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-52940</guid>
		<description>hey
i want to get all the month names using SQL Query plz help me out

thanks
tania</description>
		<content:encoded><![CDATA[<p>hey<br />
i want to get all the month names using SQL Query plz help me out</p>
<p>thanks<br />
tania</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sreekanth</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-52799</link>
		<dc:creator>sreekanth</dc:creator>
		<pubDate>Sat, 06 Jun 2009 13:00:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-52799</guid>
		<description>hi,
am sreekanth, i have a table with some columns and date of update.i am writing function which takes month and year as parameters.i want max date of update  from table  where date of update &lt;=(month and year) how to write a query.plz reply me to the mail  if u know the solution</description>
		<content:encoded><![CDATA[<p>hi,<br />
am sreekanth, i have a table with some columns and date of update.i am writing function which takes month and year as parameters.i want max date of update  from table  where date of update &lt;=(month and year) how to write a query.plz reply me to the mail  if u know the solution</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Smitha</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-52548</link>
		<dc:creator>Smitha</dc:creator>
		<pubDate>Fri, 29 May 2009 21:01:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-52548</guid>
		<description>Found your queries helpful</description>
		<content:encoded><![CDATA[<p>Found your queries helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-50306</link>
		<dc:creator>Brian Tkatch</dc:creator>
		<pubDate>Tue, 31 Mar 2009 20:02:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-50306</guid>
		<description>@Vanessa

How about: SysDate &gt;= DATEADD(m, 36, VISIT_date)

Though, 36 months is 3 years, so: SysDate &gt;= DATEADD(yy, 3, VISIT_date)</description>
		<content:encoded><![CDATA[<p>@Vanessa</p>
<p>How about: SysDate &gt;= DATEADD(m, 36, VISIT_date)</p>
<p>Though, 36 months is 3 years, so: SysDate &gt;= DATEADD(yy, 3, VISIT_date)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vanessa</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-50292</link>
		<dc:creator>Vanessa</dc:creator>
		<pubDate>Tue, 31 Mar 2009 14:38:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-50292</guid>
		<description>Hello,

I tried to create the SQL statement with the condition:

 “Today’s date &gt; Month 36 after first VISIT_date” ?

 I would think about 36 months * 30 days as:

 (SysDate -   VISIT_date) &gt; (36*30)

 
But not every month has 30 days. Can any one help pls?

Thanks,

-Vanessa</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I tried to create the SQL statement with the condition:</p>
<p> “Today’s date &gt; Month 36 after first VISIT_date” ?</p>
<p> I would think about 36 months * 30 days as:</p>
<p> (SysDate &#8211;   VISIT_date) &gt; (36*30)</p>
<p>But not every month has 30 days. Can any one help pls?</p>
<p>Thanks,</p>
<p>-Vanessa</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-49489</link>
		<dc:creator>Brian Tkatch</dc:creator>
		<pubDate>Thu, 19 Mar 2009 13:16:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-49489</guid>
		<description>@Verdel

Make the date March 1st, then subtract a day: select dateadd(yyyy, -1, dateadd(m, +1, dateadd(dd, - (datepart(dd, @period) - 1), @period)))</description>
		<content:encoded><![CDATA[<p>@Verdel</p>
<p>Make the date March 1st, then subtract a day: select dateadd(yyyy, -1, dateadd(m, +1, dateadd(dd, &#8211; (datepart(dd, @period) &#8211; 1), @period)))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Verdel</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-49405</link>
		<dc:creator>Verdel</dc:creator>
		<pubDate>Wed, 18 Mar 2009 13:58:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-49405</guid>
		<description>How do you get last day of month prior year for February where prior year was leap year?

Using the example above:

declare @period smalldatetime
set @period = &#039;2/28/2009&#039;

select cast(floor(cast(dateadd(yy,-1,dateadd(ms,-3,dateadd(mm,datediff(m,0,@period)+1,0)))as float)) as datetime)

Result:  2/28/2008

Need result to be 2/29/2008</description>
		<content:encoded><![CDATA[<p>How do you get last day of month prior year for February where prior year was leap year?</p>
<p>Using the example above:</p>
<p>declare @period smalldatetime<br />
set @period = &#8216;2/28/2009&#8242;</p>
<p>select cast(floor(cast(dateadd(yy,-1,dateadd(ms,-3,dateadd(mm,datediff(m,0,@period)+1,0)))as float)) as datetime)</p>
<p>Result:  2/28/2008</p>
<p>Need result to be 2/29/2008</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tejasnshah</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-47432</link>
		<dc:creator>tejasnshah</dc:creator>
		<pubDate>Thu, 26 Feb 2009 05:53:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-47432</guid>
		<description>Hi,

Here you can use computed column to get Age At contribution Date.

Example:

CREATE TABLE t1(
contribution_date	DATETIME, 
Dob					DATETIME
)

INSERT INTO t1 (contribution_date, DOB) VALUES(NULL, &#039;1977-07-01&#039;
)

ALTER TABLE t1
ADD AgeAtContribution AS DATEDIFF(yy, DOB, contribution_date)

SELECT * from t1

You can also find my blog to add computed column at: 
http://tejasnshah.wordpress.com/2008/12/24/how-to-add-computed-column-sql-server-2005/

Thanks,

Tejas Shah</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Here you can use computed column to get Age At contribution Date.</p>
<p>Example:</p>
<p>CREATE TABLE t1(<br />
contribution_date	DATETIME,<br />
Dob					DATETIME<br />
)</p>
<p>INSERT INTO t1 (contribution_date, DOB) VALUES(NULL, &#8216;1977-07-01&#8242;<br />
)</p>
<p>ALTER TABLE t1<br />
ADD AgeAtContribution AS DATEDIFF(yy, DOB, contribution_date)</p>
<p>SELECT * from t1</p>
<p>You can also find my blog to add computed column at:<br />
<a href="http://tejasnshah.wordpress.com/2008/12/24/how-to-add-computed-column-sql-server-2005/" rel="nofollow">http://tejasnshah.wordpress.com/2008/12/24/how-to-add-computed-column-sql-server-2005/</a></p>
<p>Thanks,</p>
<p>Tejas Shah</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aak</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-47347</link>
		<dc:creator>aak</dc:creator>
		<pubDate>Wed, 25 Feb 2009 10:15:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-47347</guid>
		<description>Hi,

I want to claculate age say for eg.

Tab1
-------
contribution_date      Dob                  AgeAtContribution
15-12-2005               01-07-1977      ?


Want to calculate age at the time of contribution_date with the help of dob column above.

Thanks,
aak</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I want to claculate age say for eg.</p>
<p>Tab1<br />
&#8212;&#8212;-<br />
contribution_date      Dob                  AgeAtContribution<br />
15-12-2005               01-07-1977      ?</p>
<p>Want to calculate age at the time of contribution_date with the help of dob column above.</p>
<p>Thanks,<br />
aak</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sanil</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-46905</link>
		<dc:creator>Sanil</dc:creator>
		<pubDate>Thu, 19 Feb 2009 09:49:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-46905</guid>
		<description>Hi, 

Can you help me to get a query in SQL server that gives me the date of last saturday of every month

Thanks,
Sanil</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>Can you help me to get a query in SQL server that gives me the date of last saturday of every month</p>
<p>Thanks,<br />
Sanil</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: karthik</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-45516</link>
		<dc:creator>karthik</dc:creator>
		<pubDate>Sat, 10 Jan 2009 11:24:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-45516</guid>
		<description>Hi i want the query to find the maximum date in a particular table.

Thanks,
Karthi..</description>
		<content:encoded><![CDATA[<p>Hi i want the query to find the maximum date in a particular table.</p>
<p>Thanks,<br />
Karthi..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nuStreet</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-45454</link>
		<dc:creator>nuStreet</dc:creator>
		<pubDate>Thu, 08 Jan 2009 07:07:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-45454</guid>
		<description>Hi,

For each month we have many weeks, some month will have 4 weeks but some will have 6 weeks ( for example for jan 09 , 01 -03 jan will be considered as Week1). How to find out the week number as per the above logic.

If i give a date the query should return it belongs wich week of the month.

i tried with datepart and week , but it returns week number for the year not for the month

Thanks</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>For each month we have many weeks, some month will have 4 weeks but some will have 6 weeks ( for example for jan 09 , 01 -03 jan will be considered as Week1). How to find out the week number as per the above logic.</p>
<p>If i give a date the query should return it belongs wich week of the month.</p>
<p>i tried with datepart and week , but it returns week number for the year not for the month</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Malar</title>
		<link>http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-44850</link>
		<dc:creator>Malar</dc:creator>
		<pubDate>Tue, 16 Dec 2008 14:13:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/#comment-44850</guid>
		<description>can anybody help me to find out second,third,fourth,fifth tuesday,wed,thu,fri,sat,sun of a month?

thanx</description>
		<content:encoded><![CDATA[<p>can anybody help me to find out second,third,fourth,fifth tuesday,wed,thu,fri,sat,sun of a month?</p>
<p>thanx</p>
]]></content:encoded>
	</item>
</channel>
</rss>
