<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BlogmyQuery - BMQ &#187; Sql Server</title>
	<atom:link href="http://blogmyquery.com/index.php/tag/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogmyquery.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 15:17:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DateFirst in SQL Server</title>
		<link>http://blogmyquery.com/index.php/2009/07/datefirst-in-sql-server/</link>
		<comments>http://blogmyquery.com/index.php/2009/07/datefirst-in-sql-server/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 20:07:28 +0000</pubDate>
		<dc:creator>kranthi</dc:creator>
				<category><![CDATA[Sqlserver]]></category>
		<category><![CDATA[DateFirst]]></category>
		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">http://blogmyquery.com/?p=600</guid>
		<description><![CDATA[Select @@DateFirst

returns the current value, for a session, of SET DATE FIRST, i.e it returns first day of week, TinyInt Value from 1 through 7 representing Monday to Sunday as shown Below. ]]></description>
			<content:encoded><![CDATA[<pre class="brush: plain;">
Select @@DateFirst
</pre>
<p>returns the current value, for a session, of SET DATE FIRST, i.e it returns first day of week, TinyInt Value from 1 through 7 representing Monday to Sunday as shown Below. </p>
<pre class="brush: plain;">
1 for Monday
2 for Tuesday
3 for Wednesday
4 for Thursday
5 for Friday
6 for Saturday
7 for Sunday
</pre>
<p>For Example, If the first day of week is Sunday (US) , Then @@DateFirst would return 7.</p>
<p>If the first day of week is Monday (Europe), Then @@DateFirst Would return 1.</p>
<pre class="brush: plain;">
SET DateFirst = 3
</pre>
<p>The above statement would set Wednesday as first day of the week for the current Session.</p>
<p>&#8216;July 1st 2009 is a wednesday</p>
<pre class="brush: plain;">
SET DateFirst = 1 -- or SET LANGUAGE Italian;
Select DATEPART(dw, '20090701')
</pre>
<p>would return 3 (since Wednesday is 3rd day from Monday)</p>
<pre class="brush: plain;">
SET DateFirst = 7 -- or SET LANGUAGE us_english;
Select DATEPART(dw, '20090701')
</pre>
<p>would return 4 (since Wednesday is 4th day from Sunday)</p>
<p>DATEPART return the weekday according @@DateFirst.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2009/07/datefirst-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculate businessdays between two dates</title>
		<link>http://blogmyquery.com/index.php/2009/07/calculate-businessdays-between-two-dates/</link>
		<comments>http://blogmyquery.com/index.php/2009/07/calculate-businessdays-between-two-dates/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 18:55:21 +0000</pubDate>
		<dc:creator>jackjeetu1</dc:creator>
				<category><![CDATA[Sqlserver]]></category>
		<category><![CDATA[Calc Business Days]]></category>
		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">http://blogmyquery.com/?p=593</guid>
		<description><![CDATA[This Example shows how to calculate the calculate the workdays between two given dates.
CREATE FUNCTION dbo.GetBusinessDays
(
@startDate SMALLDATETIME,
@endDate SMALLDATETIME
)
RETURNS INT
AS
BEGIN
DECLARE @dateDiff [...]]]></description>
			<content:encoded><![CDATA[<p>This Example shows how to calculate the calculate the workdays between two given dates.</p>
<p><span style="color: #800000;">CREATE FUNCTION dbo.GetBusinessDays<br />
(<br />
@startDate SMALLDATETIME,<br />
@endDate SMALLDATETIME<br />
)<br />
RETURNS INT<br />
AS<br />
BEGIN<br />
DECLARE @dateDiff INT;</span></p>
<p><span style="color: #800000;">SET @dateDiff = DATEDIFF(DAY, @startDate, @endDate)+1;</span></p>
<p><span style="color: #800000;">RETURN<br />
(<br />
SELECT @dateDiff/ 7 * 5 + CASE </span><span style="color: #800000;">WHEN </span><span style="color: #800000;">(@dateDiff % 7) = 0 THEN 0</span></p>
<p><span style="color: #800000;">ELSE<br />
</span></p>
<p><span style="color: #800000;"> CASE<br />
When (DATEPART(WEEKDAY, @endDate ) + @@DateFirst -1)%7 = 0 and </span><span style="color: #800000;">(@dateDiff % 7) =1 </span><span style="color: #800000;">Then </span><span style="color: #800000;">(@dateDiff % 7)-1</span><span style="color: #800000;"> &#8211;If it is sunday</span></p>
<p><span style="color: #800000;"> When (DATEPART(WEEKDAY, @endDate ) + @@DateFirst -1)%7 = 0 and </span><span style="color: #800000;">(@dateDiff % 7) &lt;&gt;1 </span><span style="color: #800000;"> </span><span style="color: #800000;"> </span><span style="color: #800000;">Then </span><span style="color: #800000;">(@dateDiff % 7)-2</span><span style="color: #800000;"> &#8211;If it is sunday<br />
</span></p>
<p><span style="color: #800000;"> When (DATEPART(WEEKDAY, @endDate ) </span><span style="color: #800000;">+ @@DateFirst</span><span style="color: #800000;"> -1)%7 =6 </span><span style="color: #800000;"> Then (@dateDiff % 7) &#8211; 1   &#8211;If it is Saturday</span></p>
<p><span style="color: #800000;">ELSE (@dateDiff % 7)<br />
END &#8212; Inner Case<br />
</span></p>
<p><span style="color: #800000;">END<br />
</span></p>
<p><span style="color: #800000;">);<br />
END</span></p>
<p><span style="color: #800000;"><span id="more-593"></span></span></p>
<p><span style="color: #000000;">There are many other ways of achieving this , you can also look at the following examples</span></p>
<p><span style="color: #800000;"><br />
</span></p>
<p><span style="color: #800000;">CREATE FUNCTION dbo.GetWorkingDays<br />
(<br />
@startDate SMALLDATETIME,<br />
@endDate   SMALLDATETIME<br />
)<br />
RETURNS INT<br />
AS<br />
BEGIN<br />
DECLARE @range INT;</span></p>
<p><span style="color: #800000;">SET @range = DATEDIFF(DAY, @startDate, @endDate)+1;</span></p>
<p><span style="color: #800000;">RETURN<br />
(<br />
SELECT<br />
@range / 7 * 5 + @range % 7 -<br />
(<br />
SELECT COUNT(*)<br />
FROM<br />
(<br />
SELECT 1 AS d<br />
UNION ALL SELECT 2<br />
UNION ALL SELECT 3<br />
UNION ALL SELECT 4<br />
UNION ALL SELECT 5<br />
UNION ALL SELECT 6<br />
UNION ALL SELECT 7<br />
) weekdays<br />
WHERE d &lt;= @range % 7<br />
AND DATENAME(WEEKDAY, @endDate &#8211; d + 1)<br />
IN<br />
(<br />
&#8216;Saturday&#8217;,<br />
&#8216;Sunday&#8217;<br />
)<br />
)<br />
);<br />
END<br />
GO</span></p>
<p><span style="color: #800000;"><span style="color: #000000;">or this that i found on one of the forums</span></span></p>
<pre><span style="color: #800000;">DECLARE @start_date DATETIME;
DECLARE @end_date DATETIME;

SET @start_date = '20080820';
SET @end_date = '20080825';

SELECT ((total_days / 7) * 5 + total_days % 7 -
CASE WHEN 6 BETWEEN start_weekday AND end_weekday
THEN 1 ELSE 0 END -
CASE WHEN 7 BETWEEN start_weekday AND end_weekday
THEN 1 ELSE 0 END)
FROM (SELECT total_days, start_weekday,
start_weekday + total_days % 7 - 1
FROM (SELECT DATEDIFF(day, @start_date, @end_date) + 1,
DATEPART(WEEKDAY, @start_date + @@DATEFIRST - 1)
) AS T(total_days, start_weekday)
) AS D(total_days, start_weekday, end_weekday);</span>
</pre>
<p><span style="color: #000000;">NOTE : This example doesnot holidays other than saturday and sunday into account.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2009/07/calculate-businessdays-between-two-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing Distributed Queries</title>
		<link>http://blogmyquery.com/index.php/2006/04/optimizing-distributed-queries/</link>
		<comments>http://blogmyquery.com/index.php/2006/04/optimizing-distributed-queries/#comments</comments>
		<pubDate>Thu, 06 Apr 2006 20:10:00 +0000</pubDate>
		<dc:creator>QueryOptTeam</dc:creator>
				<category><![CDATA[Sqlserver]]></category>
		<category><![CDATA[Optimizing Distributed Queries]]></category>
		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:570251</guid>
		<description><![CDATA[<P>I saw a post in one of the newsgroups today that referenced a piece of information Microsoft published on how the Optimizer makes decisions about remoting certain operations.</P>
<P><A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/optimsql/odp_tun_1a_6oxf.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/optimsql/odp_tun_1a_6oxf.asp</A></P>
<P>It's slightly out-of-date, and I'll work on trying to get it updated.&#160; Specifically, SQL 2005 will remote uniqueidentifiers (and it will support statistics over them as well).&#160; We'll remote queries from SQL 2005 to SQL 2000 that contain filters comparing columns to constant uniqueidentifier values as well.</P>
<P>We published a research paper last year on how the Distributed Query feature works in more detail.&#160; While it does not cover every practical detail of the implementation, you may find it as an interesting reference if you use distributed queries.</P>
<P><A href="http://citeseer.ist.psu.edu/732761.html">http://citeseer.ist.psu.edu/732761.html</A></P>
<P>If you have other remoting questions/problems, please post comments on them and we'll see if we can get them answered for you.</P>
<P>Thanks,</P>
<P>Conor</P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=570251" width="1" height="1">]]></description>
			<content:encoded><![CDATA[<p>
I saw a post in one of the newsgroups today that referenced a piece of information Microsoft published on how the Optimizer makes decisions about remoting certain operations.
</p>
<p>
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/optimsql/odp_tun_1a_6oxf.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/optimsql/odp_tun_1a_6oxf.asp</a>
</p>
<p>
It's slightly out-of-date, and I'll work on trying to get it updated.  Specifically, SQL 2005 will remote uniqueidentifiers (and it will support statistics over them as well).  We'll remote queries from SQL 2005 to SQL 2000 that contain filters comparing columns to constant uniqueidentifier values as well.
</p>
<p>
We published a research paper last year on how the Distributed Query feature works in more detail.  While it does not cover every practical detail of the implementation, you may find it as an interesting reference if you use distributed queries.
</p>
<p>
<a href="http://citeseer.ist.psu.edu/732761.html">http://citeseer.ist.psu.edu/732761.html</a>
</p>
<p>
If you have other remoting questions/problems, please post comments on them and we'll see if we can get them answered for you.
</p>
<p>
Thanks,
</p>
<p>
Conor
</p>
<p>
Source : http://blogs.msdn.com/queryoptteam/default.aspx
</p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2006/04/optimizing-distributed-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

