<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>SQL/Data</title><link>http://ryanfarley.com/blog/category/58.aspx</link><description>SQL/Data</description><managingEditor>Ryan Farley</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Ryan Farley</dc:creator><title>MERGE in SQL 2008</title><link>http://ryanfarley.com/blog/archive/2007/09/12/38120.aspx</link><pubDate>Wed, 12 Sep 2007 07:57:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2007/09/12/38120.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/38120.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2007/09/12/38120.aspx#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/38120.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/38120.aspx</trackback:ping><description>&lt;P&gt;A co-worker pointed out to me something cool that is coming in SQL 2008. A new keyword for MERGE has been introduced. This new type of statement reduces some of the tedious work you typically do when adding data to a table in SQL. As things are now, you will check for the existence of a row, and then proceed to update the matched row if it exists, or insert the new data if the matching row did not exist. The new MERGE keyword allows you to do this all in a single statement.&lt;/P&gt;
&lt;P&gt;This new MERGE statement reduces the following pseudo code:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: green"&gt;/*
    -- save parent table data
    If Data Indentifier found in Parent Data Table
        Update Data
    Else
        Insert Data
    End

    -- save child table data
    Delete from Child Data Table all items not in Data
    Update Child Data Table with all items in Data
    Insert into Child Data Table all new items in Data
*/&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;To the following:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: green"&gt;/*
    -- save parent table data
    MERGE Data to Parent Data Table

    -- save child table data
    MERGE Data to Chid Data Table
*/&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;
&lt;DIV class=link&gt;Read more: &lt;A href="http://www.sqlservercentral.com/columnists/jSebastian/3122.asp"&gt;SQL Server 2008 - The Power of Merge&lt;/A&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/38120.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ryan Farley</dc:creator><title>SQL Queries to Analyze SharePoint Usage</title><link>http://ryanfarley.com/blog/archive/2006/05/30/23103.aspx</link><pubDate>Tue, 30 May 2006 11:45:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2006/05/30/23103.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/23103.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2006/05/30/23103.aspx#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/23103.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/23103.aspx</trackback:ping><description>&lt;P&gt;I came across this list on CodeProject of SQL Queries to analyze SharePoint details and usage. This is an awesome list. Granted it does bypass the SBS object model so isn't the recommended route, but still a great list of queries you could use to make reporting on your SharePoint sites a breeze.&lt;/P&gt;
&lt;P&gt;
&lt;DIV class=link&gt;&lt;A href="http://www.codeproject.com/dotnet/QueriesToAnalyzeSPUsage.asp" target=_blank&gt;Useful SQL Queries to Analyze and Monitor SharePoint Portal Solutions Usage&lt;/A&gt; &lt;/DIV&gt;
&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/23103.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ryan Farley</dc:creator><title>Top 30 Popular Posts</title><link>http://ryanfarley.com/blog/archive/2006/05/25/22689.aspx</link><pubDate>Thu, 25 May 2006 11:41:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2006/05/25/22689.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/22689.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2006/05/25/22689.aspx#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/22689.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/22689.aspx</trackback:ping><description>&lt;P&gt;I started this blog in August of 2003, almost 3 years ago. I've made 176 posts in those 3 years. I don't post too often to my blog because I'm not all that big on posting stories about my kids, wife, dog, etc - although those do come in every now and then. Anyway, even when I have lulls where I am not posting as much, my traffic seems to stay pretty consistent. I'm actually amazed at how much traffic I get, especially when I consider how often I get around to posting (big thanks to all the visitors over the years). &lt;/P&gt;
&lt;P&gt;Some of my posts have apparently been useful :-), so I thought I would post the top 30 most popular posts I've made over the years (based on total number of unique views to the posts).&lt;/P&gt;
&lt;P&gt;
&lt;BLOCKQUOTE style="FONT-STYLE: normal"&gt;&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/12/21/1325.aspx"&gt;1. Set Focus to an ASP.NET Control&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Setting focus to controls in your&amp;nbsp;ASP.NET application&amp;nbsp;is a part of giving your end users the feel that they have come to expect. Making your web applications act more like Windows applications is a key to success (IMO). While setting focus to con...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;371,568&lt;/i&gt; - Posted on: 21-Dec-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/12/23/1330.aspx"&gt;2. Using the Web Browser Control in your C# Applications&lt;/a&gt;&lt;/b&gt;&lt;br&gt;It can be a powerful thing to display dynamic HTML in your C# applications. It can give your applications a modern look and feel and can make displaying data in non-standard ways easy with some simple markup. We have the web browser ActiveX control that wr...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;232,037&lt;/i&gt; - Posted on: 23-Dec-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/07/13/879.aspx"&gt;3. Writing to Your .NET Application's Config File&lt;/a&gt;&lt;/b&gt;&lt;br&gt;There's likely been times that you might have thought that it would make things convenient to write back to your .NET application's config file. The framework provides simple methods for reading from the config file, but gives you nothing for writing value...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;197,345&lt;/i&gt; - Posted on: 13-Jul-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/12/19/1313.aspx"&gt;4. Tips for SQL Server Identity Columns&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Tips on allowing inserts to identity columns and also for reseeding the identity value for a table....&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;117,941&lt;/i&gt; - Posted on: 19-Dec-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/01/07/261.aspx"&gt;5. Multiple Monitors rule&lt;/a&gt;&lt;/b&gt;&lt;br&gt;I love multiple monitors. I can't even imagine trying to work without multiple monitors and don't think I could ever go back to a single monitor....&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;96,533&lt;/i&gt; - Posted on: 7-Jan-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2005/08/23/8540.aspx"&gt;6. Unable to Start Debugging on the Web Server&lt;/a&gt;&lt;/b&gt;&lt;br&gt;I hate that, and it seems that every time I (or a co-worker) gets the error &amp;#8220;Unable to Start Debugging on the Web Server&amp;#8221; on a machine when attempting to debug an ASP.NET project, I have to scramble to remember what to look at. Here's a few things that has...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;91,037&lt;/i&gt; - Posted on: 23-Aug-2005 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/05/16/649.aspx"&gt;7. Stop Hijacking my Browser!&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Often in applications you have the need to launch a browser window to a specified URL. I recently evaluated various RSS readers where links to blog posts could be launched in an external browser window. What I found was that most of these applications woul...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;90,029&lt;/i&gt; - Posted on: 16-May-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2005/03/11/1886.aspx"&gt;8. Determining the Control that Caused a PostBack&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Many times you might need to perform some action on an ASP.NET postback based on the control that caused the postback to occur. Some scenarios for this might include a form with many regions, each having it's own CustomValidator and the ability to perform...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;69,089&lt;/i&gt; - Posted on: 11-Mar-2005 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2005/01/14/1439.aspx"&gt;9. Solving problems through programming...and why the Skype API sucks&lt;/a&gt;&lt;/b&gt;&lt;br&gt;I love to take the approach of solving computing problems through programming. Sometimes it backfires and I over-complicate the problem (I have been known to prematurely generalize from time to time). But usually I bask in the greatness of being a programm...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;60,149&lt;/i&gt; - Posted on: 14-Jan-2005 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/05/05/599.aspx"&gt;10. Enabling XP Themes in your .NET Applications&lt;/a&gt;&lt;/b&gt;&lt;br&gt;When you build Windows applications in .NET, by default your application will not have support for XP Themes, or Visual Styles. It is an easy enough task to do, and I think it goes a long way in giving your application a complete and professional look &amp; fe...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;49,397&lt;/i&gt; - Posted on: 5-May-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2005/02/15/1689.aspx"&gt;11. On the Subject of Dates in T-SQL&lt;/a&gt;&lt;/b&gt;&lt;br&gt;While we're on the subject of dates in T-SQL, I never liked getting the month and year for a date and sticking an '01' in the middle (then casting it all back to a datetime) to get the first day of the month for a given date value. Then you do the same to...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;42,317&lt;/i&gt; - Posted on: 15-Feb-2005 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2005/02/14/1685.aspx"&gt;12. Determining if a Date is a Weekday in T-SQL&lt;/a&gt;&lt;/b&gt;&lt;br&gt;I was reminded of a SQL function to determine if a date was a weekday or a weekend I wrote a while back when I saw the requirements of a project a colleague was working on. You'll see this requirement fairly often in many business applications. A company m...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;40,265&lt;/i&gt; - Posted on: 14-Feb-2005 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/06/08/766.aspx"&gt;13. Awesome web.config Changes in ASP.NET 2.0&lt;/a&gt;&lt;/b&gt;&lt;br&gt;There are some really cool changes coming in ASP.NET's web.config files that I am really excited about. I'll just point out a few that I've used (I hate going back to 1.1 because I can't use them). The web.config file in ASP.NET 2.0 allows you to set a lot...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;40,145&lt;/i&gt; - Posted on: 8-Jun-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/12/18/1300.aspx"&gt;14. Setting the Value of a TextBox with TextMode=Password&lt;/a&gt;&lt;/b&gt;&lt;br&gt;When the TextMode property of an ASP.NET TextBox is set to Password the value set in the Text property will not display at runtime. This can be a pain, however it is actually by design to prevent the unmasked password from being displayed in the HTML sourc...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;36,984&lt;/i&gt; - Posted on: 18-Dec-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/10/25/1127.aspx"&gt;15. T-SQL Olympics&lt;/a&gt;&lt;/b&gt;&lt;br&gt;OK, there is not an Olympics for T-SQL - but there should be. A friend of mine and I were talking the other day about &amp;#8220;gold-medal&amp;#8221; T-SQL we've come accross. The one that wins the gold for me is the code I found a long time ago on SQL Server Central from Ma...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;36,617&lt;/i&gt; - Posted on: 25-Oct-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/03/01/390.aspx"&gt;16. T-SQL: SET vs SELECT when assigning variables&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Do you know what the difference is between using SET and SELECT when assigning varaibles in T-SQL? Well, there is a difference. I came accross a great article by Narayana Vyas Kondreddi from the UK that describes the difference between the two....&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;36,204&lt;/i&gt; - Posted on: 1-Mar-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/12/27/1334.aspx"&gt;17. Interacting with the Web Browser Control&lt;/a&gt;&lt;/b&gt;&lt;br&gt;In my last post, I outlined some ways to make the Web Browser control more useful in your C# applications, to include things such as printing and setting the text or html of the browser dynamically. That is all good, but in a typical application it does li...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;35,885&lt;/i&gt; - Posted on: 27-Dec-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/04/12/526.aspx"&gt;18. Disabling the Windows Close action&lt;/a&gt;&lt;/b&gt;&lt;br&gt;There are times that you'll see a Window that has a close button in the titlebar, but it is disabled. This is often found in applications where the dialog/window changes it's status past a stoppable point so the Windows close action is removed so the user...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;35,796&lt;/i&gt; - Posted on: 12-Apr-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/03/23/465.aspx"&gt;19. Creating a IWin32Window from a Win32 Handle&lt;/a&gt;&lt;/b&gt;&lt;br&gt;There are times when you are integrating your .NET applications with other existing applications that you cannot modify and is possibly even non-.NET application. This can often result in problems integrating your .NET application's windows with the other...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;35,465&lt;/i&gt; - Posted on: 23-Mar-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/05/14/629.aspx"&gt;20. In Search of the Perfect RSS Reader&lt;/a&gt;&lt;/b&gt;&lt;br&gt;For the last year or two, I've been switching from reader to reader. While each one had features that I loved, they all seemed to fall short on one thing or another and I was never really 100% pleased with any of them. I went from SharpReader, to RSSBandit...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;33,384&lt;/i&gt; - Posted on: 14-May-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2005/02/17/1712.aspx"&gt;21. Flattening Out Data with One of the Coolest SQL Tricks Ever&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Not sure why, but I seem to be on a T-SQL kick lately - so here's another T-SQL post. One of my favorite T-SQL hacks ever is one that can flatten out data by taking a value from multiple rows and concatenating the values into a single string....&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;33,281&lt;/i&gt; - Posted on: 17-Feb-2005 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/06/16/788.aspx"&gt;22. Dynamically Loading Master Pages in ASP.NET 2.0&lt;/a&gt;&lt;/b&gt;&lt;br&gt;One of the cool new things introduced in ASP.NET 2.0 is Master Pages. Master Pages give you the ability to define a master page layout and look that is used throughout a site to give a consistent look &amp; feel to all pages. Any updates or changes to the look...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;33,156&lt;/i&gt; - Posted on: 16-Jun-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/05/10/605.aspx"&gt;23. Communication between applications via Windows Messages&lt;/a&gt;&lt;/b&gt;&lt;br&gt;At times I'll build a suite of related, but separate applications. Even though each application is a separate executable, I like to be able to integrate the applications so they can work together. Sending messages between your applications is a great way t...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;31,548&lt;/i&gt; - Posted on: 10-May-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2005/09/06/9208.aspx"&gt;24. Rendering Size (and other things) Correctly in FireFox&lt;/a&gt;&lt;/b&gt;&lt;br&gt;One thing that I just can't stand, is when a web page I build looks different in FireFox than how it looks in IE. Well, who doesn't?! The thing that really sucks is that there are things build in to how ASP.NET works that will cause this to happen. So unle...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;31,325&lt;/i&gt; - Posted on: 6-Sep-2005 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/05/26/737.aspx"&gt;25. Returning Objects from Web Services&lt;/a&gt;&lt;/b&gt;&lt;br&gt;When I work with web services I want things to work the same way as if I were working with a local layer that returns objects, not data. I don't want my code outside of the service to even see the data, just the objects that represent the data. Who doesn't...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;27,545&lt;/i&gt; - Posted on: 26-May-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2005/02/23/1739.aspx"&gt;26. Disabling Auto-Complete on ASP.NET Forms&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Popular browsers, such as Internet Explorer and Firefox support something called Auto-Complete. You've seen this many times. You go to a online form and as you start to type in fields you get a drop-down showing values you've typed in that field before. Th...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;26,844&lt;/i&gt; - Posted on: 23-Feb-2005 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/08/19/966.aspx"&gt;27. Intersection of Date Ranges&lt;/a&gt;&lt;/b&gt;&lt;br&gt;A friend of mine called me yesterday about a scheduling application he is working on. His question was so simple, or so it seemed, but it really drove me nuts. Basically he just wanted to find out if two date ranges intersected at all. Simple enough. It wa...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;24,593&lt;/i&gt; - Posted on: 19-Aug-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2006/01/11/14992.aspx"&gt;28. Tricking out the Desktop&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Something I have always been a sucker for is tricking out my desktop. I love any kind of tweak or gadget that enhances my pc and the whole user-experience thing. It's one of the many reasons I am looking forward to Vista. I've been a fan of applications th...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;24,497&lt;/i&gt; - Posted on: 11-Jan-2006 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/04/03/495.aspx"&gt;29. Retrieving database independent schema information&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Something that I think is often overlooked in the .NET Framework is the cool stuff you can get at using OleDbSchemaGuid to retrieve database schema information. I just thought of this again earlier today when I was reviewing a C# database application where...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;21,989&lt;/i&gt; - Posted on: 3-Apr-2004 &lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;img src="/skins/ryanfarleyxpblue/images/icon-tip.gif" align="absmiddle"&gt; &lt;b&gt;&lt;A href="http://ryanfarley.com/blog/archive/2004/06/10/773.aspx"&gt;30. Creating Tracking Images for ASP.NET&lt;/a&gt;&lt;/b&gt;&lt;br&gt;Often with web applications you want to track traffic statistics to get a general idea of the number of visitors viewing a resource. Whether it be a web page, an RSS feed, an e-mail or whatever, you might want an inconspicuous way to determine that it has...&lt;br&gt;&lt;b&gt;Total views: &lt;i&gt;21,725&lt;/i&gt; - Posted on: 10-Jun-2004 &lt;/b&gt;&lt;/BLOCKQUOTE&gt;
&lt;/P&gt;
&lt;P&gt;Some of these are not as relevant now with .NET 2.0, so I guess I better get back on the bandwagon ;-)&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/22689.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ryan Farley</dc:creator><title>SQL Reporting Services Tip - Launching Reports</title><link>http://ryanfarley.com/blog/archive/2006/01/27/15689.aspx</link><pubDate>Fri, 27 Jan 2006 08:44:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2006/01/27/15689.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/15689.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2006/01/27/15689.aspx#Feedback</comments><slash:comments>78</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/15689.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/15689.aspx</trackback:ping><description>&lt;P&gt;I&amp;nbsp;was playing around with various ways to launch&amp;nbsp;SQL Reporting Services reports and came across a good tip. If you work with SRS then you'll likely know you can launch a report by simply accessing the Uri to the report. For example, to launch/display a report called MyReport (at the root of the report server) you would launch the following in a browser:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;http://MYSERVER/ReportServer?MyReport&amp;amp;rs:Command=Render&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;BTW, you can also omit the &amp;#8220;&lt;FONT face="Courier New"&gt;rs:Command=Render&lt;/FONT&gt;&amp;#8221; at the end since that will be the default behavior anyway. But something cool you can also do (and this is the tip part I wanted to share) is that there are also other RS&amp;nbsp;format types&amp;nbsp;available that you can&amp;nbsp;specify to export the report directly. If you wanted to export the same report automatically to Excel you would use the following Uri to the report:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;http://MYSERVER/ReportServer?MyReport&amp;amp;rs:Command=Render&amp;amp;rs:Format=Excel&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;That is pretty cool. If you wanted to export the report to a CSV file (or other formats too)&amp;nbsp;you can specify that as well, and even indicate the delimiter too. For example, to export to CSV and use a Tab (ascii 9) as the delimiter you would use the following:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;http://MYSERVER/ReportServer?MyReport&amp;amp;rs:Command=Render&amp;amp;rs:Format=CSV&amp;amp;rc:FieldDelimiter=%09&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;You can use any of the following: HTMLOWC, MHTML, PDF, IMAGE (for a Tiff file), CSV, and XML.&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/15689.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ryan Farley</dc:creator><title>Favorite New Features of SSIS</title><link>http://ryanfarley.com/blog/archive/2006/01/13/15094.aspx</link><pubDate>Fri, 13 Jan 2006 15:50:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2006/01/13/15094.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/15094.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2006/01/13/15094.aspx#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/15094.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/15094.aspx</trackback:ping><description>&lt;P&gt;I have to say it, I love the new&amp;nbsp;SQL Server 2005 Integration Services (SSIS). Wow. There is some really awesome stuff in there that really just blow me away. There are so many new things in SSIS that I just love - too many to mention. However, it is some of the smaller, less noticed,&amp;nbsp;features that have come to be my favorites. Here are my top 3 small features in SSIS (so far).&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://files.farleyzone.com/images/1.gif" align=bottom border=0&gt; The new&amp;nbsp;DTSX extension is now associated to SSIS. When you save a SSIS package as a file (which I find I do quite often now with SQL2005 instead of saving them in the msdb). What this association does is two things; 1) You&amp;nbsp;can double click on a DTSX file and get a dialog to edit the package properties, such as connections, commands, configurations, etc (see dialog below). You can also execute the package from this dialog. Just awesome.&lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://files.farleyzone.com/images/dtsx_file.jpg" target=_blank alt="Click for larger image"&gt;&lt;IMG src="http://files.farleyzone.com/images/th_dtsx_file.jpg" border=0&gt;&lt;/A&gt;&lt;BR&gt;&lt;I&gt;(Click for larger image)&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;All you need to do is double-click a DTSX file to get this dialog (or right-click and select 'Open'). No need to run dtsrunui and then browse for it like you would have to with DTS files (but that wouldn't give you the same ability to edit properties like you can here, only global vars), although you &lt;EM&gt;can&lt;/EM&gt; still do that if you want to for saved DTSX files (or any SSIS package) by running DTExecUI. If you right-click on a DTSX file you can select 'Edit' which will open the package in Visual Studio's BI designer&amp;nbsp;for editing.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://files.farleyzone.com/images/2.gif" align=bottom border=0&gt; You have complete control over flow. The part where this really hit me is the granularity of control you have over flow for individual column transforms. &lt;/P&gt;
&lt;P align=center&gt;&lt;IMG src="http://files.farleyzone.com/images/ssis_cols.jpg" border=0&gt;&lt;/P&gt;
&lt;P&gt;You can specify to redirect any rows where a certain column's lengh might be truncated or where there might have been an error for the data in a critical column. The redirect thing just blows my mind. How did we ever survive without that in old-school DTS? (I'll tell you how, with a lot of pain in the butt flow control and failing tasks just because some non-important value would have been truncated. That just sucked). Control is good. More detail the better.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://files.farleyzone.com/images/3.gif" align=bottom border=0&gt; The Package Explorer rules. Not much more you can say there.&lt;/P&gt;
&lt;P align=center&gt;&lt;IMG src="http://files.farleyzone.com/images/ssis_pkg_props.jpg" border=0&gt;&lt;/P&gt;
&lt;P&gt;You have a complete bird's-eye view of the entire package. But not just for viewing, but also for a quick and easy way to modify properties in the package. No need to go around clicking on tasks or other items in the designer, you just have the hierarchy of items in the package and can easily select one and modify it's properties in an easy to use standard property list. Way too cool.&lt;/P&gt;
&lt;P&gt;It's those small things that make me so happy *snif*.&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/15094.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ryan Farley</dc:creator><title>Flattening Out Data with One of the Coolest SQL Tricks Ever</title><link>http://ryanfarley.com/blog/archive/2005/02/17/1712.aspx</link><pubDate>Thu, 17 Feb 2005 17:38:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2005/02/17/1712.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/1712.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2005/02/17/1712.aspx#Feedback</comments><slash:comments>32</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/1712.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/1712.aspx</trackback:ping><description>&lt;P&gt;Not sure why, but I seem to be on a T-SQL kick lately - so here's another T-SQL post. One of my favorite T-SQL hacks ever is one that can flatten out data by taking a value from multiple rows and concatenating the values into a single string. &lt;/P&gt;
&lt;P&gt;Let's say, for example, that you have a &amp;#8220;training class&amp;#8221; table&amp;nbsp;with a 1:M child table containing dates the class will be held&amp;nbsp;and you want to just have a single string that lists the dates for&amp;nbsp;each class. Or maybe that you have a &amp;#8220;project&amp;#8221; table with a 1:M child, each row containing a person assigned to that project and you want to have a list of all the members of the project like this: &amp;#8220;Ryan Farley, Bobo Brown, Joe Blow&amp;#8221;. Apparently this trick has been around a while. I first learned of it from &lt;A href="http://www.objectrolemodeling.com/" target=_blank&gt;Scot Becker&lt;/A&gt; a year or so ago and I've loved it ever since.&lt;/P&gt;
&lt;P&gt;
&lt;DIV class=link&gt;&lt;A href="http://objectrolemodeling.com/posts/188.aspx" target=_blank&gt;SQL Hack or SQL Trick on ObjectRoleModeling.com&lt;/A&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Take a look at this example of parent-child tables and their data:&lt;/P&gt;
&lt;P&gt;
&lt;DIV align=center&gt;&lt;IMG src="http://files.farleyzone.com/images/parent-child_data.gif" border=0&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Now, if I wanted to get a single string of child records for a given parent I could do this:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;declare&lt;/SPAN&gt; @list &lt;SPAN style="COLOR: blue"&gt;varchar&lt;/SPAN&gt;(1000)
&lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; @list = &lt;SPAN style="COLOR: navy"&gt;''&lt;/SPAN&gt;

&lt;SPAN style="COLOR: blue"&gt;select&lt;/SPAN&gt; @list = @list + fieldvalue + &lt;SPAN style="COLOR: navy"&gt;' '&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;from&lt;/SPAN&gt; childtable &lt;SPAN style="COLOR: blue"&gt;where&lt;/SPAN&gt; parentid = @id

&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; @list&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;This would result in the following value returned for the ParentID of 1:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;Value 1-1 Value 1-2 Value 1-3&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;This can have some cool uses. Let's say you want to kick out something to a customer outlining the products in their order. Just the names delimited by commas. You could use this (using the Northwind database)&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;declare&lt;/SPAN&gt; @prodlist &lt;SPAN style="COLOR: blue"&gt;varchar&lt;/SPAN&gt;(1000) 
&lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; @prodlist = &lt;SPAN style="COLOR: navy"&gt;''&lt;/SPAN&gt;

&lt;SPAN style="COLOR: blue"&gt;select&lt;/SPAN&gt; 
    @prodlist = @prodlist + p.productname + &lt;SPAN style="COLOR: navy"&gt;', '&lt;/SPAN&gt; 

&lt;SPAN style="COLOR: blue"&gt;from&lt;/SPAN&gt;
    orders o 

    &lt;SPAN style="COLOR: blue"&gt;inner&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;join&lt;/SPAN&gt; [order details] o2 
    &lt;SPAN style="COLOR: blue"&gt;on&lt;/SPAN&gt; o.orderid = o2.orderid 

    &lt;SPAN style="COLOR: blue"&gt;inner&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;join&lt;/SPAN&gt; products p 
    &lt;SPAN style="COLOR: blue"&gt;on&lt;/SPAN&gt; o2.productid = p.productid 

&lt;SPAN style="COLOR: blue"&gt;where&lt;/SPAN&gt; 
    o.orderid = @id

&lt;SPAN style="COLOR: green"&gt;--trim off extra comma at end
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; @prodlist &amp;lt;&amp;gt; &lt;SPAN style="COLOR: navy"&gt;''&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; @prodlist = &lt;SPAN style="COLOR: blue"&gt;left&lt;/SPAN&gt;(@prodlist, len(@prodlist) - 2)

&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; @prodlist&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Now you'll have a comma delimited string of products for the order to use as you need. No cursors/loops used. I've used this in many different ways, from listing a string of dates for an event, or even building a Page1/Page2/Page3.aspx kind of&amp;nbsp;URL&amp;nbsp;for hierarchical pages in a CMS/portal system. Quite a cool trick IMO.&lt;/P&gt;
&lt;P&gt;A few things to keep in mind. This is in no way an optimal route if you have a lot of rows of data to work with. This will be slow with medium to large sets of data. You can only use a single field in this since it is an assigning select statement and cannot be mixed with data-retrieval, so the usual route is to stick it in a function where you pass in a ID and get back the string. Add the call to the function in your data-retrieving select statement and things will get slow if you have the potential for a large amount of rows. But with that said, Scot's post outlines a few crude speed tests and states the following:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;EM&gt;To do an unscientific performance test, I created a table loaded with a million numbers and summed them via a) the TSQL sum aggregate function, b) the method above and c) a cursor. On my (old) laptop, the sum function took 1,350 milliseconds, the method above took 1,213 milliseconds, and the cursor took 67,206 milliseconds.&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the trick fits the need, I use it. This one is the cat's meow. I fell in love with this one the moment I read it from Scot a year+ ago. You had me at &lt;FONT face="Courier New"&gt;select @s = @s + person_name&lt;/FONT&gt; ;-)&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/1712.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ryan Farley</dc:creator><title>On the Subject of Dates in T-SQL</title><link>http://ryanfarley.com/blog/archive/2005/02/15/1689.aspx</link><pubDate>Tue, 15 Feb 2005 08:07:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2005/02/15/1689.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/1689.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2005/02/15/1689.aspx#Feedback</comments><slash:comments>19</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/1689.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/1689.aspx</trackback:ping><description>&lt;P&gt;&lt;A href="http://ryanfarley.com/blog/archive/2005/02/14/1685.aspx"&gt;While we're on the subject of dates in T-SQL&lt;/A&gt;, I never liked getting the month and year for a date and sticking an '01' in the middle (then casting it all back to a datetime) to get the first day of the month for a given date value. Then you do the same to get the end date by getting the first day of the next month and subtract a 1 from it. This way is much better. And by &lt;EM&gt;better&lt;/EM&gt; I mean &lt;EM&gt;cooler&lt;/EM&gt; ;-)&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;declare&lt;/SPAN&gt; @date &lt;SPAN style="COLOR: blue"&gt;datetime&lt;/SPAN&gt;
&lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; @date = getdate()

&lt;SPAN style="COLOR: green"&gt;--get first day of month 
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;select&lt;/SPAN&gt; dateadd(m, datediff(m, 0, @date), 0)

&lt;SPAN style="COLOR: green"&gt;--get last day of month 
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;select&lt;/SPAN&gt; dateadd(m, datediff(m, 0, dateadd(m, 1, @date)), -1)&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/1689.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ryan Farley</dc:creator><title>Determining if a Date is a Weekday in T-SQL</title><link>http://ryanfarley.com/blog/archive/2005/02/14/1685.aspx</link><pubDate>Mon, 14 Feb 2005 15:37:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2005/02/14/1685.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/1685.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2005/02/14/1685.aspx#Feedback</comments><slash:comments>25</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/1685.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/1685.aspx</trackback:ping><description>&lt;P&gt;I was reminded of a SQL function to determine if a date was a weekday or a weekend&amp;nbsp;I wrote a while back when I saw&amp;nbsp;the requirements of a project a colleague was working on. You'll see this requirement fairly often in many business applications. A company might want to span certain activities over business or working days only.&amp;nbsp;The requirement might be to&amp;nbsp;only include business days in certain calculations. Either way, there are a few things to keep in mind when making this calculation.&lt;/P&gt;
&lt;P&gt;Making the calculation can be very simple. It is easy code to write. However, in order to make sure the calculation works with the server's regional settings in mind you need to understand how the date settings effect the SQL date functions. A great example of&amp;nbsp;the role that&amp;nbsp;regional settings play in the results&amp;nbsp;of the SQL date functions is outlined in this Informit.com article by Baya Pavliashvili:&lt;/P&gt;
&lt;P&gt;
&lt;DIV class=link&gt;&lt;A href="http://www.informit.com/articles/article.asp?p=24041" target=_blank&gt;SQL Server: Determining Whether a Date is a Business Day&lt;/A&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The first day of the week can vary from country to country. In the US the week begins on Sunday, which is day 7 according to SQL server). Some calendars begin the week on Monday (which is day 1 according to SQL). However, getting the weekday datepart will return Sunday as 1 and Saturday as 7. The problem comes into play with international regional settings, where Sunday is not the start of the week, because the @@DATEFIRST setting in SQL is changed according to the calendar used, which then will effect the result from getting the weekday datepart (since it returns the value based on the @@DATEFIRST value). The solution to this is to take the @@DATEFIRST value into account in your calculation. As you can see from the article mentioned above that took a short trivial piece of code and turned it into a long drawn-out function. &lt;/P&gt;
&lt;P&gt;I don't like long code when it could be shortened. Sure it might be easier to read, but I like to keep things short &amp;amp; compact. I take the @@DATEFIRST value minus 1 and add that to the weekday datepart minus 1. Then if that result modulus 7 equals either 5 or 6 then you have a weekend (Saturday or Sunday).&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;create&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;function&lt;/SPAN&gt; fn_IsWeekDay 
(
    @date &lt;SPAN style="COLOR: blue"&gt;datetime&lt;/SPAN&gt; 
)
&lt;SPAN style="COLOR: blue"&gt;returns&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bit&lt;/SPAN&gt; 
&lt;SPAN style="COLOR: blue"&gt;as&lt;/SPAN&gt; 
&lt;SPAN style="COLOR: blue"&gt;begin&lt;/SPAN&gt; 

    &lt;SPAN style="COLOR: blue"&gt;declare&lt;/SPAN&gt; @dtfirst &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;
    &lt;SPAN style="COLOR: blue"&gt;declare&lt;/SPAN&gt; @dtweek &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; 
    &lt;SPAN style="COLOR: blue"&gt;declare&lt;/SPAN&gt; @iswkday &lt;SPAN style="COLOR: blue"&gt;bit&lt;/SPAN&gt; 

    &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; @dtfirst = @@datefirst - 1
    &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; @dtweek = datepart(weekday, @date) - 1

    &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (@dtfirst + @dtweek) % 7 &lt;SPAN style="COLOR: blue"&gt;not&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; (5, 6)
        &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; @iswkday = 1 &lt;SPAN style="COLOR: green"&gt;--business day
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;
        &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; @iswkday = 0 &lt;SPAN style="COLOR: green"&gt;--weekend
&lt;/SPAN&gt;
    &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; @iswkday
&lt;SPAN style="COLOR: blue"&gt;end&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Short and sweet.&amp;nbsp;Now you can simply do this:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; dbo.fn_IsWeekDay(@date) = 1 
&lt;SPAN style="COLOR: blue"&gt;begin&lt;/SPAN&gt; 
    &lt;SPAN style="COLOR: green"&gt;--do some magic here ;-)
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;end&lt;/SPAN&gt; 

&lt;SPAN style="COLOR: green"&gt;--or &lt;/SPAN&gt;

&lt;SPAN style="COLOR: blue"&gt;select&lt;/SPAN&gt; a.SomeFieldsForCalculation &lt;SPAN style="COLOR: blue"&gt;from&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;table&lt;/SPAN&gt; a 
&lt;SPAN style="COLOR: blue"&gt;where&lt;/SPAN&gt; dbo.fn_IsWeekDay(a.SomeDateField) = 1 &lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;and all is good.&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/1685.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ryan Farley</dc:creator><title>Tips for SQL Server Identity Columns</title><link>http://ryanfarley.com/blog/archive/2004/12/19/1313.aspx</link><pubDate>Sun, 19 Dec 2004 20:39:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2004/12/19/1313.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/1313.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2004/12/19/1313.aspx#Feedback</comments><slash:comments>51</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/1313.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/1313.aspx</trackback:ping><description>&lt;P&gt;&lt;STRONG&gt;Allowing inserts to identity columns:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If you are inserting data from some other source to a table with an identity column and you need to ensure you retain the indentity values, you can temporarily allow inserts to the indentity column. Without doing so explicitly you will receive an error if you attempt to insert a value into the indentity column. For example, if I have a table named MYTABLE and I want to allow inserts into it's identity column, I can execute the following:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: Courier New"&gt;set&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue; FONT-FAMILY: Courier New"&gt;identity_insert&lt;/SPAN&gt; mytable &lt;SPAN style="COLOR: blue; FONT-FAMILY: Courier New"&gt;on&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;/P&gt;
&lt;P&gt;Once you execute the command you will be able to insert values into the table's identity column. This will stay in effect in until you turn it off by executing the following:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: Courier New"&gt;set&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue; FONT-FAMILY: Courier New"&gt;identity_insert&lt;/SPAN&gt; mytable &lt;SPAN style="COLOR: blue; FONT-FAMILY: Courier New"&gt;off&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;/P&gt;
&lt;P&gt;Be aware that at any time, only a single table in a session can have the identity_insert set to on.&amp;nbsp; If you attempt to enable this for a table and another table already has this enabled, you will receive an error and will not be able to do so until you first turn this off for the other table. Also, if the value used for the indentity is larger than the current identity&amp;nbsp;value then the&amp;nbsp;new value will be used for the identity seed for the column. &amp;nbsp;&lt;/P&gt;
&lt;br&gt;
&lt;P&gt;&lt;STRONG&gt;Reseeding the identity value:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;You can reseed the indentity value, that is, to have the identity values reset or start at a new predefined value by using &lt;FONT face="Courier New"&gt;DBCC CHECKIDENT&lt;/FONT&gt;.&amp;nbsp; For example, if I have a table named MYTABLE and I want to reseed the indentity column to 30 I would execute the following:&lt;/P&gt;
&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue; FONT-FAMILY: Courier New"&gt;dbcc checkident&lt;/SPAN&gt; (mytable, reseed, 30)&lt;/PRE&gt;
&lt;/P&gt;
&lt;P&gt;If you wanted to reseed the table to start with an identity of 1 with the next insert then you would reseed the table's identity to 0.&amp;nbsp; The identity seed is what the value is currently at, meaning that the next value will increment the seed and use that.&amp;nbsp; However, one thing to keep in mind is that if you set the identity seed below values that you currently have in the table, that you will violate the indentity column's uniqueness constraint as soon as the values start to overlap.&amp;nbsp; The identity value will not just &amp;#8220;skip&amp;#8221; values that already exist in the table.&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/1313.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Ryan Farley</dc:creator><title>SQL Enterprise Manager Tip</title><link>http://ryanfarley.com/blog/archive/2004/12/14/1292.aspx</link><pubDate>Tue, 14 Dec 2004 15:06:00 GMT</pubDate><guid>http://ryanfarley.com/blog/archive/2004/12/14/1292.aspx</guid><wfw:comment>http://ryanfarley.com/blog/comments/1292.aspx</wfw:comment><comments>http://ryanfarley.com/blog/archive/2004/12/14/1292.aspx#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://ryanfarley.com/blog/comments/commentRss/1292.aspx</wfw:commentRss><trackback:ping>http://ryanfarley.com/blog/services/trackbacks/1292.aspx</trackback:ping><description>&lt;P&gt;I'm in the &lt;A href="http://scottonwriting.net/sowblog/posts/2801.aspx" target=_blank&gt;same boat as Scott Mitchell&lt;/A&gt;&amp;nbsp;on this one. I practically live inside of SQL Enterprise Manager. Been using it for years abd years. But I never knew about this. You can go to the table listing and CTRL+C then go to a text editor and CTRL+V to paste the selected table's CREATE TABLE statement. No need to go through the Generate SQL Scripts menu option, just copy away. It works with multiple tables selected too,&amp;nbsp;and also&amp;nbsp;with views, procs, etc.&lt;/P&gt;&lt;img src ="http://ryanfarley.com/blog/aggbug/1292.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>