<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/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>SQL Server DBA </title>
        <link>http://community.dotnetwork.it/Excentric/category/72.aspx</link>
        <description>SQL Server DBA </description>
        <language>en-US</language>
        <copyright>Sabrina C.</copyright>
        <managingEditor>ziayeye@ziayeye.it</managingEditor>
        <generator>Subtext Version 1.9.5.176</generator>
        <item>
            <title>Moving a Team Foundation Server 2010 from a domain to another</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/11/01/moving-a-team-foundation-server-2010-from-a-domain-to.aspx</link>
            <description>&lt;p&gt;This is the list of what we did a couple of weeks ago in my organization, moving our development TFS from a domain to another domain, I write it here in case someone else needs it and of course to find it out if I ever need this again.&lt;/p&gt;
&lt;p&gt;First thing to do is read carefully the TFS documentation on this matter, starting with the MSDN document titled &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/ms404883(printer).aspx"&gt;Move Team Foundation Server from One Environment to Another&lt;/a&gt; and reading carefully what to do in your specific case. Our move was the simplest one, We needed to move Our Single Server from domain XXX to domain YYY without changing anything.&lt;/p&gt;
&lt;p&gt;The first thing we did was a full backup of all the TFS databases from our SQL Server 2008. Then, we did a Ghost of the Server Hard Disk, to be sure to have the possibility to Rollback in case of problems.&lt;/p&gt;
&lt;p&gt;Then the procedure we followed was this:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;We created the same service users we had on our present environment on the new domain, this means, the TfsService user, the SQLService user, the Proxy User and other domain users required by the system and we give them the same passwords.&lt;/li&gt;
    &lt;li&gt;We opened the TFS configuration and write down on a notepad all user groups and all TFS groups and WIndows groups and users mapped to every TFS project inside our server paying attention to write down everything. This operation is important because the Group and User mapping on project will be cleared during the moving and to avoid developers from “Screaming” and “cursing you” because they’ve lost access to their projects you have to be careful on this.&lt;/li&gt;
    &lt;li&gt;Another important thing to remember is DO NOT CHANGE THE NAME OF THE SERVER IN THE NEW ENVIRONMENT this is Very Important, because SQL Server 2008 has some problems when you rename its instance under it’s nose. So if you change the servers naming in the new domain, for your sake, move your old servers with the same name and let them Die with that name.&lt;/li&gt;
    &lt;li&gt;After this, You have to kill the TFS services, you can do that using the TFSServiceControl command line utilities which is located under the Tools folder of the TFS 2010 installation folder. &lt;br /&gt;
    TfsServiceControl quiesce  &lt;br /&gt;
    is the command to shut down the services.&lt;/li&gt;
    &lt;li&gt;You also have to shut down IIS if you have sharepoint on the same machine and SQL Server services.&lt;/li&gt;
    &lt;li&gt;Now you have to move the server to the new domain, Remember to activate a local system Administrator User with a simple password, use a domain administrator with the rights to do so to remove the server from the old domain. Restart it, verify that the services are still stopped or stop them again using the local Administrator.&lt;/li&gt;
    &lt;li&gt;Remember also to activate the SA user with a password you know or to create a SQL Server user with SysAdmin rights giving it a password of your choice.&lt;/li&gt;
    &lt;li&gt;Join the server to the new domain. Change the Service users for SQL Server and TFS services to the one in the new domain and start SQL Server, do not yet start TFS.&lt;/li&gt;
    &lt;li&gt;Then you first need to open the SQL Server Management Studio and log on using SA or your personal Sysadmin, go to the Security folder and verify that local machine Windows Groups have mantained their rights. Then map the new domain Windows Groups or users you had on the old domain and assign them rights and roles on the TFS databases. Remove database mappings from the old users before deleting them.&lt;/li&gt;
    &lt;li&gt;You also need to go to the Users management of the local Server, and if you created local groups containing domain users or groups, you need to remap the users and groups from the new domain.&lt;/li&gt;
    &lt;li&gt;Then you need to use the Identities Command, which is one of the options provided by the TFSConfig command line utility of TFS to change inside the configuration database of TFS the SIDs of the Domain Users used to run TFS Services, the utility stays on the Tools folder of the TFS installation. There is an article on the msdn linked to the guide I linked at the beginning of this article that gives you all the informations on how to use it. The command is something like: &lt;br /&gt;
    TFSConfig Identities /change /fromdomain:olddomain /todomain:newdomain /account:accountname /toaccount:accountname &lt;br /&gt;
                               /sqlinstance:sqlserverinstancename /databasename:TfsConfigDatabase /account:sqlaccountname &lt;br /&gt;
    If you Kept instance names and user names and passwords identical on the two domains this is a simple routine operation and all works at first shot. So keep clearly in mind, no Server name change, no service user change, no password change.&lt;/li&gt;
    &lt;li&gt;In the unfortunate case you had to change a service user, there is another command of the TFSConfig utility, named Accounts, you can use to specify to TFS the new service accounts before executing the Identities command. &lt;/li&gt;
    &lt;li&gt;After this you can restart TFS using the TfsServiceControl unquiesce command.&lt;/li&gt;
    &lt;li&gt;Open the TFS configuration manager, go back to the User Access and permission configuration and restore for each project the Windows Users and groups and the TFS users and Groups that have been erased by the domain move. With a particular care for the Project collection valid users, Team Foundation Licensed Users whicy you find if your first installation was a Workgroup TFS is no more needed.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After this procedures are completed, you can open a Visual Studio 2010 and attach to the TFS client from a computer in the new domain, if you did all well, the server will respond exactly as it responded on the old domain.&lt;/p&gt;
&lt;p&gt;I didn’t speak of Sharepoint, well we are a small team and don’t use sharepoint, but the migration guide gives you all the instruction to migrate also Sharepoint services, so I’m sure it works correctly.&lt;/p&gt;
&lt;div style="PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; FLOAT: none; PADDING-TOP: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8b39fb62-ffa0-4c3e-baff-083af42a96a0" class="wlWriterEditableSmartContent"&gt;Technorati Tag: &lt;a rel="tag" href="http://technorati.com/tags/TFS"&gt;TFS&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/SQL+Server+2008"&gt;SQL Server 2008&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/542.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/11/01/moving-a-team-foundation-server-2010-from-a-domain-to.aspx</guid>
            <pubDate>Mon, 01 Nov 2010 07:23:03 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/542.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/11/01/moving-a-team-foundation-server-2010-from-a-domain-to.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/542.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Remote debugging from Visual Studio 2010 some tips on real world experience.</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/10/17/remote-debugging-from-visual-studio-2010-some-tips-on-real.aspx</link>
            <description>&lt;p&gt;This is a shadow post, I write all here as always to be able to find it when I need it, but I’m just the writer, the real experiment was done by my colleague Luca, who loves writing code but hates writing documentation, blogs, articles and speech in public conferences… I still hope to convince him open a blog but my chances are poor.&lt;/p&gt;
&lt;p&gt;Anyway this is it:&lt;/p&gt;
&lt;p&gt;We had a strange behaviour on a machine for a new installed application, the machine was on a different domain from the development machines, and we wanted to remote debug it, here is what we did:&lt;/p&gt;
&lt;p&gt;On the remote machine you want to debug you start mswsmon, the remote debug utility.   &lt;br /&gt;
on tools&amp;gt;options you can choose between:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;No Authentication&lt;/li&gt;
    &lt;li&gt;Windows Authentication&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Choosing number one, you can debug, but we were not able to load debug symbols, so searching for the problem was not easy not having code to look for. Even copying the .pdb files on the installation folder was useless.&lt;/p&gt;
&lt;p&gt;Choosing number two, being the destination machine on a different domain we had to do the following:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Create a local user on development machine and remote machine with administrator privileges and same password. Even though on the remote machine we think you just need Remote debug permissions.&lt;/li&gt;
    &lt;li&gt;Disable the firewall on both machines (We are sure we needed just a couple of ports enabled, but had no time to search them, and being on the same network, in the same office it was easier to do).&lt;/li&gt;
    &lt;li&gt;Using mswsmon, on the remote machine, logged with the user that had the problem with the application, create a server named &lt;a href="mailto:UserName@MachineName"&gt;UserName@MachineName&lt;/a&gt; where UserName is the name of the local user created on point 1. Start the application to debug.&lt;/li&gt;
    &lt;li&gt;Log on the development machine with the local user and password, open Visual Studio 2010, open remote debug using     &lt;br /&gt;
    Debug&amp;gt;Attach to process, choose:
    &lt;ul&gt;
        &lt;li&gt;Transport = default (Windows Authentication)&lt;/li&gt;
        &lt;li&gt;Qualifier = &lt;a href="mailto:UserName@MachineName"&gt;UserName@MachineName&lt;/a&gt; (the one set on point 3)&lt;/li&gt;
        &lt;li&gt;Search for the process, double click and confirm.&lt;/li&gt;
        &lt;li&gt;You are now attached to the process running on the remote machine.&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;We experimented also that if you have the same version of the program on Remote and Development machine, if you don’t have the .pdb files on the remote machine, you can use Debug&amp;gt;Windows&amp;gt;Modules window to search for the module or dll you are attached to and using context menu (right click) you can load symbols (PDB) from a file on the development machine.&lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/527.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/10/17/remote-debugging-from-visual-studio-2010-some-tips-on-real.aspx</guid>
            <pubDate>Sun, 17 Oct 2010 13:31:07 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/527.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/10/17/remote-debugging-from-visual-studio-2010-some-tips-on-real.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/527.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Database owner change</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/10/17/database-owner-change.aspx</link>
            <description>&lt;p&gt;Yesterday I was in the middle of a very rare kind of operation in my company IT System, we are changing our Domain, moving all computers and servers from a domain to another.&lt;/p&gt;  &lt;p&gt;One of the servers we moved is the TFS development server on which there is a SQL Server 2008 holding all our code and projects. The move to the new domain gave no problems at all, but as recommended we did not change the computer name.&lt;/p&gt;  &lt;p&gt;After the move we had to add the domain users and groups of the new domain to SQL Server replacing the domain users and groups of the old domain and we had no troubles in doing this operation except for one thing.&lt;/p&gt;  &lt;p&gt;Accessing the Properties of a database I had an error because the Database Owner was invalid and the Properties window for that database did not open at all.&lt;/p&gt;  &lt;p&gt;The problem is due to the fact that databases are Owned by the User that creates them, and the TFS Databases were owned by the user used for the installation. I suggest to those who administer a TFS SQL server to change the Database Owner to SA for all databases.&lt;/p&gt;  &lt;p&gt;Anyway it is not a big trouble, to take ownership of databases, what you need is to log in as a Sysadmin (SA would be the better), onto SQL Server and run the following script changing the USE clause to each database with Ownership problems and run it.&lt;/p&gt;  &lt;pre&gt;use DatabaseName
exec sp_changedbowner 'sa'&lt;/pre&gt;

&lt;p&gt;Technorati Tag: &lt;a href="http://technorati.com/tags/SQL"&gt;SQL&lt;/a&gt;,&lt;a href="http://technorati.com/tags/TSQL"&gt;TSQL&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Database"&gt;Database&lt;/a&gt;&lt;/p&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/526.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/10/17/database-owner-change.aspx</guid>
            <pubDate>Sun, 17 Oct 2010 13:03:52 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/526.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/10/17/database-owner-change.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/526.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Configure SQL Server Database Mail to send Job Notifications</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/09/16/configure-sql-server-database-mail-to-send-job-notifications.aspx</link>
            <description>&lt;p&gt;Today I was modifying the configuration of database mail on one of my company’s SQL Servers, so I decided to configure the Database mail on another server where it wasn’t yet configured. Being something made once every five years or more, I decided to publish the steps to do it, this way I can repeat the operation on my customers servers to be sure someone is alerted if something on the SQL Server goes wrong.&lt;/p&gt;  &lt;p&gt;My server is a SQL 2008 server, but the configuration is identical for SQL 2005.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail01_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail01" border="0" alt="tfsmail01" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail01_thumb.jpg" width="272" height="148" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Open the Server Management folder on SQL Management Studio and select Database Mail.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail02_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail02" border="0" alt="tfsmail02" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail02_thumb.jpg" width="544" height="484" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If it is the first configuration, leave the option as selected, elsewhere select the proper option and click NEXT.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail03_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail03" border="0" alt="tfsmail03" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail03_thumb.jpg" width="537" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Give the profile a proper name and description, Database Mail can be configured for other tasks then the simple Job notification, and you can have more than a single profile for the different tasks.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail04_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail04" border="0" alt="tfsmail04" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail04_thumb.jpg" width="604" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Click on the ADD button to create a mail account that has to be used to send the e-mails, pay attention, if you already have an account the Window above does not appear automatically, it appears first a window to select an existing account with a button that allows you to create a new one that opens this window.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail05_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail05" border="0" alt="tfsmail05" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail05_thumb.jpg" width="569" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Fill in the account data with a name and a description, set the e-mail addresses and the SMTP server name and then fill the authentication credentials if necessary or leave the anonymous authentication (for example if the company SMTP server is configured to allow so).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail06_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail06" border="0" alt="tfsmail06" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail06_thumb.jpg" width="547" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then you need to set the security data for the profile, to be able to send e-mails from the SQL Server Agent, it’s better to create a public profile.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail07_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail07" border="0" alt="tfsmail07" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail07_thumb.jpg" width="541" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;After clicking the NEXT button, you’ll see two verification and execution confirm windows, the latter shown above.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail08_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail08" border="0" alt="tfsmail08" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail08_thumb.jpg" width="156" height="41" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now select the Operators Folder inside the SQL Server Agent Objects folder and create a new Operator.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail09_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail09" border="0" alt="tfsmail09" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail09_thumb.jpg" width="529" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We just need to set the operator name and the e-mail where to send notifications, unless you want to set also Net Send and Pager for the operator.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail10_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail10" border="0" alt="tfsmail10" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail10_thumb.jpg" width="537" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In Every backup, Maintenance or Script Execution Job set inside the Agent, you need to set up the Operator, Check the E-Mail notification action and set wether to notify Job Completion or Just Job Error or Job Success.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail11_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail11" border="0" alt="tfsmail11" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail11_thumb.jpg" width="533" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now we need to right click the SQL Server Agent icon and select the Alert System, activating the Database mail profile we generated. If you don’t do this operation, the Agent ignores E-Mail notifications and does nothing, it does not give any error or warning message.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="tfsmail12" border="0" alt="tfsmail12" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/ConfigurareSQLServerDatabaseMailperlinvi_DE7D/tfsmail12_thumb.jpg" width="236" height="96" /&gt;&lt;/p&gt;  &lt;p&gt;After the configuration of the Alert System you must Restart SQL Server Agent to activate the E-mail notification system for Jobs and Alerts.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a7c637e8-5f9e-4dc2-b5ed-03cf4c14a465" class="wlWriterEditableSmartContent"&gt;Tags: &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/SQLServer+2008/default.aspx" rel="tag"&gt;SQLServer 2008&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/Job/default.aspx" rel="tag"&gt;Job&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/Alert/default.aspx" rel="tag"&gt;Alert&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/Database+Mail/default.aspx" rel="tag"&gt;Database Mail&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/512.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/09/16/configure-sql-server-database-mail-to-send-job-notifications.aspx</guid>
            <pubDate>Thu, 16 Sep 2010 14:16:52 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/512.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/09/16/configure-sql-server-database-mail-to-send-job-notifications.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/512.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How to create a Guid.Empty in SQL</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/08/10/how-to-create-a-guid.empty-in-sql.aspx</link>
            <description>&lt;p&gt;Last friday my colleague Luca was “fighting” with a problem in managing null values and GUIDs. A Guid is a value type so it is not nullable. In my stored procedures when using parameters for filtering, I use the NULL value as the default value to ignore a filter parameter.&lt;/p&gt;  &lt;p&gt;Changing the code of several classes to be able to change a Guid.Empty into a DbNull before passing it to a SELECT command was decisely not the best thing to do, so we searched a way to recreate a Guid.Empty value in SQL.&lt;/p&gt;  &lt;p&gt;We were able to create the small snippet of SQL in the following function:&lt;/p&gt;  &lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;FUNCTION&lt;/span&gt; Guid_Empty()
&lt;span class="kwrd"&gt;RETURNS&lt;/span&gt; UniqueIdentifier
&lt;span class="kwrd"&gt;AS&lt;/span&gt;
&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
&lt;span class="kwrd"&gt;RETURN&lt;/span&gt; &lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;cast&lt;/span&gt;(0 &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;binary&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; uniqueidentifier)
&lt;span class="kwrd"&gt;END&lt;/span&gt;
GO&lt;/pre&gt;

&lt;p&gt;After the creation of the above function and a simple table on my Paperinik Database,  I was able to write the following query:&lt;/p&gt;

&lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [ID]
      ,[Descrizione]
      ,[Prezzo]
      ,[Quantità]
      ,[Umi]
      ,IsNull(AltGuid, dbo.Guid_EMPTY()) &lt;span class="kwrd"&gt;AS&lt;/span&gt; Alt
  &lt;span class="kwrd"&gt;FROM&lt;/span&gt; [paperinik].[dbo].[TbRighe]&lt;/pre&gt;

&lt;p&gt;The query produces the following output:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/HowtocreateaGuid.EmptyinSQL_141CA/guidquery_2.jpg" rel="lightbox"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="guidquery" border="0" alt="guidquery" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/HowtocreateaGuid.EmptyinSQL_141CA/guidquery_thumb.jpg" width="644" height="104" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I can use it also to build a query like the one below:&lt;/p&gt;

&lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [ID]
      ,[Descrizione]
      ,[Prezzo]
      ,[Quantità]
      ,[Umi]
      ,IsNull(AltGuid, dbo.Guid_EMPTY()) &lt;span class="kwrd"&gt;AS&lt;/span&gt; Alt
  &lt;span class="kwrd"&gt;FROM&lt;/span&gt; [paperinik].[dbo].[TbRighe]
&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;
IsNull(AltGuid, dbo.Guid_EMPTY()) = dbo.Guid_EMPTY()&lt;/pre&gt;

&lt;p&gt;That allows me to filter only the Guid Empty rows, or I can use the &amp;lt;&amp;gt; to find only the rows with a non Empty Guid. This way of writing the query, is giving me the possibility to use Guid.Empty in my Code as a SQLParameter value without the need to use a Nullable Guid or to implement complicated control expressions in my C# classes.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:06fc812e-6fbb-411a-9fb5-c5c256bbe9e0" class="wlWriterEditableSmartContent"&gt;Technorati Tag: &lt;a href="http://technorati.com/tags/SQL" rel="tag"&gt;SQL&lt;/a&gt;,&lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Guid" rel="tag"&gt;Guid&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/484.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/08/10/how-to-create-a-guid.empty-in-sql.aspx</guid>
            <pubDate>Tue, 10 Aug 2010 20:53:20 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/484.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/08/10/how-to-create-a-guid.empty-in-sql.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/484.aspx</wfw:commentRss>
        </item>
        <item>
            <title>SQL Server Update a Table with values selected from another table</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/07/12/sql-server-update-a-table-with-values-selected-from-another.aspx</link>
            <description>&lt;p&gt;Today, on another step of the job started with the last post, I had the following problem, I created a table with some informations and I needed to add more informations taken from other tables.&lt;/p&gt;  &lt;p&gt;A an Example, I created an inventory table, with Article Code, Description, Quantity, to create it I used an INSERT query from the Articles table, then the users of my system inserted the Inventory values and now I need to add Sales Price and Cost of every article, reading them from the PriceList.&lt;/p&gt;  &lt;p&gt;For Simplicity my tables are as follows:&lt;/p&gt;  &lt;pre class="TsqlFormat"&gt;TbInventory
   IDInventory &lt;span class="kwrd"&gt;int&lt;/span&gt;
   IDArticle nvarchar(32)
   Quantity &lt;span class="kwrd"&gt;decimal&lt;/span&gt;(18,5)
   Price &lt;span class="kwrd"&gt;decimal&lt;/span&gt;(18,5)
   Cost &lt;span class="kwrd"&gt;decimal&lt;/span&gt;(18,5)

TbListini
   IDPricelist &lt;span class="kwrd"&gt;int&lt;/span&gt;
   IDarticle nvarchar(32)
   Price &lt;span class="kwrd"&gt;decimal&lt;/span&gt;(18,5)
   Cost &lt;span class="kwrd"&gt;decimal&lt;/span&gt; (18,5)&lt;/pre&gt;

&lt;p&gt;To update price and cost I’lluse, an Update query, with a Join.&lt;/p&gt;

&lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;UPDATE&lt;/span&gt; TbInventory
    &lt;span class="kwrd"&gt;SET&lt;/span&gt; Price = isnull(lis.Price,0)
      , Cost = isnull(lis.Cost,0)
&lt;span class="kwrd"&gt;FROM&lt;/span&gt; TbInventory inv
&lt;span class="kwrd"&gt;INNER&lt;/span&gt; &lt;span class="kwrd"&gt;JOIN&lt;/span&gt;
    TbPriceList lis
&lt;span class="kwrd"&gt;ON&lt;/span&gt;
  inv.IDArticle = lis.IDArticle  &lt;/pre&gt;

&lt;p&gt;This way, I’m setting a relation between the two tables usin ga JOIN thenI update the Inventory Table with The Price List values.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:31d404cd-266b-40d3-9641-90ce40ff82aa" class="wlWriterEditableSmartContent"&gt;Tags: &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/SQL/default.aspx" rel="tag"&gt;SQL&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/UPDATE/default.aspx" rel="tag"&gt;UPDATE&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/455.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/07/12/sql-server-update-a-table-with-values-selected-from-another.aspx</guid>
            <pubDate>Mon, 12 Jul 2010 16:40:51 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/455.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/07/12/sql-server-update-a-table-with-values-selected-from-another.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/455.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Use of Rank function to extract a list of rows with the highest date</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/07/07/use-of-rank-function-to-extract-a-list-of-rows.aspx</link>
            <description>&lt;p&gt;Today I had the problem to create a query to get the most recent price from a pricelists table. Every pricelist in the table can contain the same article any number of times with different startup dates. I made some search to find a way to obtain what i needed and I found the RANK function, it was used in a similar scenario. I publish this post as usual to remember how to use this function next time I need it and in the hope to help someone else solving similar problems.&lt;/p&gt;  &lt;p&gt;The table:&lt;/p&gt;  &lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[TbPricelistsRg](
    [IDPriceListRg] [&lt;span class="kwrd"&gt;int&lt;/span&gt;] &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [IDPriceList] [nvarchar](10) &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [IDArticle] [nvarchar](32) &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [Price] [&lt;span class="kwrd"&gt;decimal&lt;/span&gt;](18, 5) &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [StartDate] [&lt;span class="kwrd"&gt;date&lt;/span&gt;] &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
 &lt;span class="kwrd"&gt;CONSTRAINT&lt;/span&gt; [PK_TbPriceListsRg] &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt; &lt;span class="kwrd"&gt;CLUSTERED&lt;/span&gt; 
(
    [IDPriceListRg] &lt;span class="kwrd"&gt;ASC&lt;/span&gt;
)&lt;span class="kwrd"&gt;WITH&lt;/span&gt; (PAD_INDEX  = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, STATISTICS_NORECOMPUTE  = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, IGNORE_DUP_KEY = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, ALLOW_ROW_LOCKS  &lt;br /&gt;     = &lt;span class="kwrd"&gt;ON&lt;/span&gt;, ALLOW_PAGE_LOCKS  = &lt;span class="kwrd"&gt;ON&lt;/span&gt;) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;]
) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;]&lt;/pre&gt;

&lt;p&gt;Every row is linked to a PriceList through the IDPriceLIst field, we don’t need to use it for the example so it is omitted.&lt;/p&gt;

&lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [dbo].[TbPricelistsRg]
           ([IDPriceList]
           ,[IDArticle]
           ,[Price]
           ,[StartDate])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (&lt;span class="str"&gt;'CLD'&lt;/span&gt;
           ,&lt;span class="str"&gt;'ABC'&lt;/span&gt;
           ,10
           ,&lt;span class="kwrd"&gt;CONVERT&lt;/span&gt;(&lt;span class="kwrd"&gt;date&lt;/span&gt;, &lt;span class="str"&gt;'20080105'&lt;/span&gt;, 112))
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [dbo].[TbPricelistsRg]
           ([IDPriceList]
           ,[IDArticle]
           ,[Price]
           ,[StartDate])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (&lt;span class="str"&gt;'CLD'&lt;/span&gt;
           ,&lt;span class="str"&gt;'OCQ'&lt;/span&gt;
           ,14
           ,&lt;span class="kwrd"&gt;CONVERT&lt;/span&gt;(&lt;span class="kwrd"&gt;date&lt;/span&gt;, &lt;span class="str"&gt;'20080105'&lt;/span&gt;, 112))
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [dbo].[TbPricelistsRg]
           ([IDPriceList]
           ,[IDArticle]
           ,[Price]
           ,[StartDate])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (&lt;span class="str"&gt;'CLD'&lt;/span&gt;
           ,&lt;span class="str"&gt;'FYS'&lt;/span&gt;
           ,21
           ,&lt;span class="kwrd"&gt;CONVERT&lt;/span&gt;(&lt;span class="kwrd"&gt;date&lt;/span&gt;, &lt;span class="str"&gt;'20080105'&lt;/span&gt;, 112))
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [dbo].[TbPricelistsRg]
           ([IDPriceList]
           ,[IDArticle]
           ,[Price]
           ,[StartDate])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (&lt;span class="str"&gt;'CLD'&lt;/span&gt;
           ,&lt;span class="str"&gt;'MUI'&lt;/span&gt;
           ,13
           ,&lt;span class="kwrd"&gt;CONVERT&lt;/span&gt;(&lt;span class="kwrd"&gt;date&lt;/span&gt;, &lt;span class="str"&gt;'20080105'&lt;/span&gt;, 112))
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [dbo].[TbPricelistsRg]
           ([IDPriceList]
           ,[IDArticle]
           ,[Price]
           ,[StartDate])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (&lt;span class="str"&gt;'CLD'&lt;/span&gt;
           ,&lt;span class="str"&gt;'SIO'&lt;/span&gt;
           ,42
           ,&lt;span class="kwrd"&gt;CONVERT&lt;/span&gt;(&lt;span class="kwrd"&gt;date&lt;/span&gt;, &lt;span class="str"&gt;'20080105'&lt;/span&gt;, 112))
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [dbo].[TbPricelistsRg]
           ([IDPriceList]
           ,[IDArticle]
           ,[Price]
           ,[StartDate])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (&lt;span class="str"&gt;'CLD'&lt;/span&gt;
           ,&lt;span class="str"&gt;'GOU'&lt;/span&gt;
           ,18
           ,&lt;span class="kwrd"&gt;CONVERT&lt;/span&gt;(&lt;span class="kwrd"&gt;date&lt;/span&gt;, &lt;span class="str"&gt;'20080105'&lt;/span&gt;, 112))
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [dbo].[TbPricelistsRg]
           ([IDPriceList]
           ,[IDArticle]
           ,[Price]
           ,[StartDate])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (&lt;span class="str"&gt;'CLD'&lt;/span&gt;
           ,&lt;span class="str"&gt;'HOU'&lt;/span&gt;
           ,20
           ,&lt;span class="kwrd"&gt;CONVERT&lt;/span&gt;(&lt;span class="kwrd"&gt;date&lt;/span&gt;, &lt;span class="str"&gt;'20080105'&lt;/span&gt;, 112))
&lt;span class="kwrd"&gt;GO&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The previous script inserts some articles, we can repeat it changing the PriceLIst, the Dates and prices to be able to show how the query meets our needs.&lt;/p&gt;

&lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [IDPriceListRg]
      ,[IDPriceList]
      ,[IDArticle]
      ,[Price]
      ,[StartDate]
      ,RANK() &lt;span class="kwrd"&gt;OVER&lt;/span&gt; (PARTITION &lt;span class="kwrd"&gt;BY&lt;/span&gt; IDPriceList, IDArticle &lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; StartDate &lt;span class="kwrd"&gt;DESC&lt;/span&gt;) DATERANK
  &lt;span class="kwrd"&gt;FROM&lt;/span&gt; [paperinik].[dbo].[TbPricelistsRg]&lt;/pre&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;font color="#0080ff"&gt;RANK&lt;/font&gt;&lt;/strong&gt; function, allows us to indicate one or more grouping fields on which calculate ranking, this is done using the &lt;strong&gt;&lt;font color="#0080ff"&gt;PARTITION BY&lt;/font&gt;&lt;/strong&gt; keywords, in our query we indicate the two fields on which ranking has to break. The &lt;font color="#0080ff"&gt;&lt;strong&gt;ORDER BY&lt;/strong&gt;&lt;/font&gt;  keyword, instead indicates on which field we have to measure ranking. while the &lt;font color="#0080ff"&gt;&lt;strong&gt;DESC&lt;/strong&gt;&lt;/font&gt; keywords tells that we want to start from the most recent date..&lt;/p&gt;

&lt;p&gt;This is the result of our query.&lt;/p&gt;

&lt;table style="width: 296pt; border-collapse: collapse" border="0" cellspacing="0" cellpadding="0" width="395"&gt;&lt;colgroup&gt;&lt;col style="width: 48pt" width="64" /&gt;&lt;col style="width: 56pt; mso-width-source: userset; mso-width-alt: 2742" width="75" /&gt;&lt;col style="width: 48pt" width="64" /&gt;&lt;/colgroup&gt;&lt;tbody&gt;
    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="width: 48pt; height: 15pt" height="20" width="64"&gt;IDListinoRg&lt;/td&gt;

      &lt;td style="width: 48pt" width="64"&gt;IDListino&lt;/td&gt;

      &lt;td style="width: 48pt" width="64"&gt;IDArticolo&lt;/td&gt;

      &lt;td style="width: 48pt" width="64"&gt;Prezzo&lt;/td&gt;

      &lt;td style="width: 56pt" width="75"&gt;ValidoDal&lt;/td&gt;

      &lt;td style="width: 48pt" width="64"&gt;DATERANK&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;107&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;ABC&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;24/10/2010&lt;/td&gt;

      &lt;td align="right"&gt;1&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;86&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;ABC&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;15/05/2010&lt;/td&gt;

      &lt;td align="right"&gt;2&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;65&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;ABC&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;08/01/2010&lt;/td&gt;

      &lt;td align="right"&gt;3&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;44&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;ABC&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;08/09/2009&lt;/td&gt;

      &lt;td align="right"&gt;4&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;23&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;ABC&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;16/04/2009&lt;/td&gt;

      &lt;td align="right"&gt;5&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;1&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;ABC&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;05/01/2008&lt;/td&gt;

      &lt;td align="right"&gt;6&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;2&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;ABC&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;05/01/2008&lt;/td&gt;

      &lt;td align="right"&gt;6&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;109&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;FYS&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.100.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;24/10/2010&lt;/td&gt;

      &lt;td align="right"&gt;1&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;88&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;FYS&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.100.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;15/05/2010&lt;/td&gt;

      &lt;td align="right"&gt;2&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;67&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;FYS&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.100.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;08/01/2010&lt;/td&gt;

      &lt;td align="right"&gt;3&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;46&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;FYS&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.100.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;08/09/2009&lt;/td&gt;

      &lt;td align="right"&gt;4&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;25&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;FYS&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.100.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;16/04/2009&lt;/td&gt;

      &lt;td align="right"&gt;5&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;4&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;FYS&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.100.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;05/01/2008&lt;/td&gt;

      &lt;td align="right"&gt;6&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;112&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;GOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.800.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;24/10/2010&lt;/td&gt;

      &lt;td align="right"&gt;1&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;91&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;GOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.800.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;15/05/2010&lt;/td&gt;

      &lt;td align="right"&gt;2&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;70&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;GOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.800.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;08/01/2010&lt;/td&gt;

      &lt;td align="right"&gt;3&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;49&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;GOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.800.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;08/09/2009&lt;/td&gt;

      &lt;td align="right"&gt;4&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;28&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;GOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.800.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;16/04/2009&lt;/td&gt;

      &lt;td align="right"&gt;5&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;7&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;GOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;1.800.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;05/01/2008&lt;/td&gt;

      &lt;td align="right"&gt;6&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;113&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;HOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;24/10/2010&lt;/td&gt;

      &lt;td align="right"&gt;1&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;92&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;HOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;15/05/2010&lt;/td&gt;

      &lt;td align="right"&gt;2&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;71&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;HOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;08/01/2010&lt;/td&gt;

      &lt;td align="right"&gt;3&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;50&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;HOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;08/09/2009&lt;/td&gt;

      &lt;td align="right"&gt;4&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;29&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;HOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;16/04/2009&lt;/td&gt;

      &lt;td align="right"&gt;5&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr style="height: 15pt" height="20"&gt;
      &lt;td style="height: 15pt" height="20" align="right"&gt;8&lt;/td&gt;

      &lt;td&gt;CLD&lt;/td&gt;

      &lt;td&gt;HOU&lt;/td&gt;

      &lt;td class="xl63" align="right"&gt;2.000.000&lt;/td&gt;

      &lt;td class="xl64" align="right"&gt;05/01/2008&lt;/td&gt;

      &lt;td align="right"&gt;6&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;So to obtain the most recent prices, we need just to add a filter on DATERANK = 1, and to obtain the less recent price we just need to delete the DESC keyword and filter on rank 1.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:27b8a83b-f846-404d-ae0f-c3a2d70793b7" class="wlWriterEditableSmartContent"&gt;Technorati Tag: &lt;a href="http://technorati.com/tags/SQL" rel="tag"&gt;SQL&lt;/a&gt;,&lt;a href="http://technorati.com/tags/RANK" rel="tag"&gt;RANK&lt;/a&gt;,&lt;a href="http://technorati.com/tags/DATE" rel="tag"&gt;DATE&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/453.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/07/07/use-of-rank-function-to-extract-a-list-of-rows.aspx</guid>
            <pubDate>Wed, 07 Jul 2010 21:45:13 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/453.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/07/07/use-of-rank-function-to-extract-a-list-of-rows.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/453.aspx</wfw:commentRss>
        </item>
        <item>
            <title>FILESTREAM feature in SQL server 2008</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/03/04/filestream-feature-in-sql-server-2008.aspx</link>
            <description>&lt;p&gt;One of the most important new features in SQL Server 2008 is certainly the possibility to use File System to store BLOB data. So if you work with images, binary files and so on and you need to store them in a SQL server database, it is possible to use this feature. It is important for those who are using SQL Server Express edition, because it avoids the problem of the 4GB maximum size for the database giving virtually no limit to the BLOB data growth.&lt;/p&gt;  &lt;p&gt;Let’s see how to activate this feature on our server:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;First step is to activate the feature at server protocol level, so, from Programs menu &amp;gt; Microsoft SQL Server 2008 &amp;gt; Configuration Tools – launch the SQL Server Configuration Manager (icon with the red toolbox).&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Select SQL Services in the left treeview&lt;/li&gt;      &lt;li&gt;On the right window, select SQL Server (MSSQLSERVER) for the default instance or the name of the instance to configure.&lt;/li&gt;      &lt;li&gt;Right click on it, and select properties.&lt;/li&gt;      &lt;li&gt;On the property window there is a series of TABS, select FILESTREAM, activate the T-SQL access and if necessary the API access and the remote client access (I haven’t done a full test so I don’t know if this is necessary, so you have to make some tests on this.)&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Second step is in SQL Management Studio, connect to the server with an account with Sysadmin rights, on the server, right click and select properties, select Advanced on the left options list and on the first row of the property grid on the right part of the window, activate the Filestream option in T-SQL mode or Full Access.&lt;/li&gt;    &lt;li&gt;Create a Database able to memorize data on FILESTREAM:&lt;/li&gt;    &lt;ul&gt;     &lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;USE&lt;/span&gt; [master]
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

/****** &lt;span class="kwrd"&gt;Object&lt;/span&gt;:  &lt;span class="kwrd"&gt;Database&lt;/span&gt; [Paperinik]    Script &lt;span class="kwrd"&gt;Date&lt;/span&gt;: 03/04/2010 18:09:07 ******/
&lt;span class="kwrd"&gt;IF&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;EXISTS&lt;/span&gt; (&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; name &lt;span class="kwrd"&gt;FROM&lt;/span&gt; sys.databases &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; name = N&lt;span class="str"&gt;'Paperinik'&lt;/span&gt;)
&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;DATABASE&lt;/span&gt; [Paperinik] &lt;span class="kwrd"&gt;ON&lt;/span&gt;  &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; 
( NAME = N&lt;span class="str"&gt;'Paperinik'&lt;/span&gt;, FILENAME = N&lt;span class="str"&gt;'C:\SQL.DIR\Data\Test\Paperinik.mdf'&lt;/span&gt; , &lt;br /&gt;    &lt;span class="kwrd"&gt;SIZE&lt;/span&gt; = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ), 
 FILEGROUP [Binari] &lt;span class="kwrd"&gt;CONTAINS&lt;/span&gt; FILESTREAM  &lt;span class="kwrd"&gt;DEFAULT&lt;/span&gt; 
( NAME = N&lt;span class="str"&gt;'Paperinik_Bin'&lt;/span&gt;, FILENAME = N&lt;span class="str"&gt;'c:\sql.dir\data\test\PaperinikFS\paperinik_bin'&lt;/span&gt; )
 LOG &lt;span class="kwrd"&gt;ON&lt;/span&gt; 
( NAME = N&lt;span class="str"&gt;'Paperinik_log'&lt;/span&gt;, FILENAME = N&lt;span class="str"&gt;'C:\SQL.DIR\Data\Test\Paperinik_log.ldf'&lt;/span&gt; , &lt;br /&gt;   &lt;span class="kwrd"&gt;SIZE&lt;/span&gt; = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
END&lt;/pre&gt;
  &lt;/ul&gt;

  &lt;ul&gt;this example made with my favourite database :D creates the database with the Paperinik.mdf as master data file and the file Paperinik_log.ldf as a log file. Adding a FILEGROUP named Binari which defines the FILESTREAM zone, telling the server which is the filesystem folder where to put the data.  in my case, c:\sql.dir\data\test\PaperinikFS\ pay attention that the Service account needs full control on this folder.&lt;/ul&gt;

  &lt;li&gt;To proceed with test we need to create a table with a Varbinary(MAX) field with option FILESTREAM 
    &lt;ul&gt;
      &lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;USE&lt;/span&gt; [Paperinik]
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[TbFiles](
    [IDFile] [uniqueidentifier] &lt;span class="kwrd"&gt;ROWGUIDCOL&lt;/span&gt;  &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [IDFileSerial] [&lt;span class="kwrd"&gt;int&lt;/span&gt;] &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [DDFile] [nvarchar](255) &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [FileData] [varbinary](&lt;span class="kwrd"&gt;max&lt;/span&gt;) FILESTREAM  &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
 &lt;span class="kwrd"&gt;CONSTRAINT&lt;/span&gt; [PK_TbFiles] &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt; &lt;span class="kwrd"&gt;NONCLUSTERED&lt;/span&gt; 
(
    [IDFile] &lt;span class="kwrd"&gt;ASC&lt;/span&gt;
)&lt;span class="kwrd"&gt;WITH&lt;/span&gt; (PAD_INDEX  = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, STATISTICS_NORECOMPUTE  =     &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, 
    IGNORE_DUP_KEY = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, ALLOW_ROW_LOCKS  = &lt;span class="kwrd"&gt;ON&lt;/span&gt;,
    ALLOW_PAGE_LOCKS  = &lt;span class="kwrd"&gt;ON&lt;/span&gt;) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;]
) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;] FILESTREAM_ON [Binari]
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;USE&lt;/span&gt; [Paperinik]
/****** &lt;span class="kwrd"&gt;Object&lt;/span&gt;:  &lt;span class="kwrd"&gt;Index&lt;/span&gt; [UQ_TbFileSerial]    Script &lt;span class="kwrd"&gt;Date&lt;/span&gt;: 03/04/2010 17:23:33 ******/
&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;UNIQUE&lt;/span&gt; &lt;span class="kwrd"&gt;CLUSTERED&lt;/span&gt; &lt;span class="kwrd"&gt;INDEX&lt;/span&gt; [UQ_TbFileSerial] &lt;span class="kwrd"&gt;ON&lt;/span&gt; [dbo].[TbFiles] 
(
    [IDFileSerial] &lt;span class="kwrd"&gt;ASC&lt;/span&gt;
)&lt;span class="kwrd"&gt;WITH&lt;/span&gt; (PAD_INDEX  = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, STATISTICS_NORECOMPUTE  = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, 
    SORT_IN_TEMPDB = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, IGNORE_DUP_KEY = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, 
    DROP_EXISTING = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, ONLINE = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, ALLOW_ROW_LOCKS  = &lt;span class="kwrd"&gt;ON&lt;/span&gt;, 
    ALLOW_PAGE_LOCKS  = &lt;span class="kwrd"&gt;ON&lt;/span&gt;) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;] FILESTREAM_ON [Binari]
&lt;span class="kwrd"&gt;GO&lt;/span&gt;&lt;/pre&gt;
In this example, I’ve created a table to memorize some files, even though in the example I put into the table something simpler, I will made some more test and let you know how it works later on this blog.

      &lt;br /&gt;To be able to contain a FILESTREAM field, it is mandatory that the table has a GUID (uniqueidentifier) ID field, to made it more easy I added an integer unique ID to be able to find things in a more fashionable way.

      &lt;br /&gt;&lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;Now we need to insert the test data in the table, it is very simple using T-SQL:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [Paperinik].[dbo].[TbFiles]
           ([IDFile]
           ,[IDFileSerial]
           ,[DDFile]
           ,[FileData])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (NEWID()
           ,1
           ,&lt;span class="str"&gt;'Nullo'&lt;/span&gt;
           ,&lt;span class="kwrd"&gt;null&lt;/span&gt;)
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [Paperinik].[dbo].[TbFiles]
           ([IDFile]
           ,[IDFileSerial]
           ,[DDFile]
           ,[FileData])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (NEWID()
           ,2
           ,&lt;span class="str"&gt;'Vuoto'&lt;/span&gt;
           ,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="str"&gt;''&lt;/span&gt; &lt;span class="kwrd"&gt;as&lt;/span&gt; varbinary(&lt;span class="kwrd"&gt;max&lt;/span&gt;)))
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [Paperinik].[dbo].[TbFiles]
           ([IDFile]
           ,[IDFileSerial]
           ,[DDFile]
           ,[FileData])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (NEWID()
           ,3
           ,&lt;span class="str"&gt;'Stringa'&lt;/span&gt;
           ,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="str"&gt;'Questa stringa è binaria'&lt;/span&gt; &lt;span class="kwrd"&gt;as&lt;/span&gt; varbinary(&lt;span class="kwrd"&gt;max&lt;/span&gt;)))
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [Paperinik].[dbo].[TbFiles]
           ([IDFile]
           ,[IDFileSerial]
           ,[DDFile]
           ,[FileData])
     &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
           (NEWID()
           ,4
           ,&lt;span class="str"&gt;'La quarta'&lt;/span&gt;
           ,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="str"&gt;'Questa riga contiene questa stringa'&lt;/span&gt; &lt;span class="kwrd"&gt;as&lt;/span&gt; varbinary(&lt;span class="kwrd"&gt;max&lt;/span&gt;)))
GO&lt;/pre&gt;
I’ve created four rows one with a NULL binary field, one with an empty string and two with a string inside.&lt;/ul&gt;

&lt;p&gt;If we open our root folder after this operation on c:\sql.dir\data\test\PaperinikFS\ we will find some new folders, with a GUID as name, digging into the content we will find some files with names like nnnnnnnn-nnnnnnnn-nnnn that when opened with notepad will show the data in our varbinary field, the NULL field has no file. I haven’t yet tried to memorize a binary file inside this field, I’ll tell you what happens in a future post.&lt;/p&gt;

&lt;p&gt;What comes out in the end from this test? If we need to store unstructured data in a database, this can be a good solution, because SQL Server gives us transactions, logs, managed purge the possibility to activate indexing, I’ve to try Full text indexing on NON Sql Express servers, the possibility to backup these data as a normal file system directory, eliminates the 4GB database limit but pay attention, even though the BLOB data can be accessed from the file system it is not easy to find things inside this file system, it is very simple to find things and check out/check in binary data using the T-SQL or the direct acces APIs. So if you thought to use FILESYSTEM in SQL Server to be able to access data both from the database and directly from file system, this is not the right way.&lt;/p&gt;

&lt;p&gt;If you want to build a database to index informations on your non structured data and be able to keep files on the filesystem, and use them directly from where they are stored, well, you have to build something manual, and put just the “Path” info inside your database.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ec47414a-c36f-4f22-b45c-4a45b190793b" class="wlWriterEditableSmartContent"&gt;Tags: &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/SQL/default.aspx" rel="tag"&gt;SQL&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/FILESTREAM/default.aspx" rel="tag"&gt;FILESTREAM&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/SQLServer+2008/default.aspx" rel="tag"&gt;SQLServer 2008&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/373.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/03/04/filestream-feature-in-sql-server-2008.aspx</guid>
            <pubDate>Thu, 04 Mar 2010 18:19:20 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/373.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/03/04/filestream-feature-in-sql-server-2008.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/373.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How to search text inside Views SQL definition on a SQL Server database</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/01/29/how-to-search-text-inside-views-sql-definition-on-a.aspx</link>
            <description>&lt;p&gt;Scenario: There is a problem in SQL 2005 and 2008, due to Legacy functionalities of SQL 2000. In SQL 2000 it was possible to use an ORDER BY clause inside a VIEW putting a SELECT TOP 100 PERCENT in the View definition. Obviously We all used it massively :D, after the SP2 or SP3 in SQL 2005 this feature available for all databases set in SQL 2000 compatibility mode does not work anymore. &lt;/p&gt;  &lt;p&gt;I've discovered this on a production site where a nice small Access Function Developed in 2001 stopped working on October 15 2009. &lt;/p&gt;  &lt;p&gt;There is an Hot Fix (Made after SP2 but not contained in SP3) that fixes the problem &lt;a href="http://support.microsoft.com/kb/936305/" target="_blank"&gt;available here&lt;/a&gt;, but of course it is opportune for us to find out and change all views using the Order By feature and modify then the code to order things after the View. &lt;/p&gt;  &lt;p&gt;After the problem has been discovered and the fix made on the Function, the question was: &lt;/p&gt;  &lt;p&gt;How many views with an Order By do I have in this database? &lt;/p&gt;  &lt;p&gt;Searching on the internet I've found a nice small script on Stack overflow Forums so I put it here just in case: &lt;/p&gt;  &lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; 
    v.name, 
    m.definition 
&lt;span class="kwrd"&gt;FROM&lt;/span&gt;  
    sys.views v 
&lt;span class="kwrd"&gt;INNER&lt;/span&gt; &lt;span class="kwrd"&gt;JOIN&lt;/span&gt;  
    sys.sql_modules m &lt;span class="kwrd"&gt;ON&lt;/span&gt; v.object_ID = m.object_id 
&lt;span class="kwrd"&gt;WHERE&lt;/span&gt; m.definition &lt;span class="kwrd"&gt;LIKE&lt;/span&gt; &lt;span class="str"&gt;'%TOP%'&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This script allowed me to search the TOP clause in all my views definitions, and can be customized to search probably any piece of sql contained in all object definitions in a database.&lt;/p&gt;

&lt;p&gt;Thanks to &lt;a href="http://adsi.mvps.org/" target="_blank"&gt;Mark S.&lt;/a&gt; for sharing it.&lt;/p&gt;

&lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ec014b8f-06b8-49db-8aab-cf337277893a" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tag: &lt;a href="http://technorati.com/tags/SQL" rel="tag"&gt;SQL&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Order+by" rel="tag"&gt;Order by&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SortedViews" rel="tag"&gt;SortedViews&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/331.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/01/29/how-to-search-text-inside-views-sql-definition-on-a.aspx</guid>
            <pubDate>Fri, 29 Jan 2010 11:28:58 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/331.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/01/29/how-to-search-text-inside-views-sql-definition-on-a.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/331.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Some Database Modification tests</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2009/12/31/some-database-modification-tests.aspx</link>
            <description>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;If you, like me, have the misfortune to work with very creative software architects :D:D:D, you probably need to write Database Modification scripts on a daily base. It is a good practice be sure that a script executed two times in a row doesn’t throw exceptions, mainly if the script can be executed by your customers DBA (or the customers themselves). I write down here some of the most common tests, you can use when you have to Add tables, Drop Tables, Add Columns, Drop Columns or Foreign Keys. &lt;/p&gt;  &lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;IF&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;EXISTS&lt;/span&gt; (
    &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; 1 &lt;span class="kwrd"&gt;FROM&lt;/span&gt; sysobjects &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; xtype=&lt;span class="str"&gt;'u'&lt;/span&gt; 
       &lt;span class="kwrd"&gt;AND&lt;/span&gt; name=&lt;span class="str"&gt;'MyTable'&lt;/span&gt;)
    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
       &lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; Mytable …;
    END&lt;/pre&gt;

&lt;p&gt;Without the NOT this can be used also to Drop Tables.&lt;/p&gt;

&lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;IF&lt;/span&gt; &lt;span class="kwrd"&gt;EXISTS&lt;/span&gt; (&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;FROM&lt;/span&gt; sys.foreign_keys &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; object_id = &lt;br /&gt;    OBJECT_ID(&lt;span class="str"&gt;'[FK_MyForeignKeyConstraintName]'&lt;/span&gt;) &lt;br /&gt;    &lt;span class="kwrd"&gt;AND&lt;/span&gt; parent_object_id = OBJECT_ID(&lt;span class="str"&gt;'[MyTable]'&lt;/span&gt;))
    &lt;span class="kwrd"&gt;ALTER&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [MyTable] &lt;span class="kwrd"&gt;DROP&lt;/span&gt; &lt;span class="kwrd"&gt;CONSTRAINT&lt;/span&gt; [FK_MyForeignKeyConstraintName]&lt;/pre&gt;

&lt;p&gt;If you need to delete a table with Relations, it is better drop the Constraints before dropping the table. If you Add a Constraint you can set a NOT before Exists and avoid trying to create a constraint already present.&lt;/p&gt;

&lt;pre class="TsqlFormat"&gt;&lt;span class="kwrd"&gt;IF&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;EXISTS&lt;/span&gt; (&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; 1 &lt;span class="kwrd"&gt;FROM&lt;/span&gt; sys.columns &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; object_id=object_id(&lt;span class="str"&gt;'MyTable'&lt;/span&gt;) &lt;span class="kwrd"&gt;AND&lt;/span&gt; name=&lt;span class="str"&gt;'MyColumnName'&lt;/span&gt;)
    &lt;span class="kwrd"&gt;ALTER&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; MyTable &lt;span class="kwrd"&gt;ADD&lt;/span&gt; MyColumnName &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;;&lt;/pre&gt;

&lt;p&gt;This one is useful when Adding, or without NOT, Dropping columns.&lt;/p&gt;

&lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:134f10a2-992c-4c1f-9dfb-00922833361b" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Tags: &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/SQL/default.aspx" rel="tag"&gt;SQL&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/DBMaintenance/default.aspx" rel="tag"&gt;DBMaintenance&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/284.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2009/12/31/some-database-modification-tests.aspx</guid>
            <pubDate>Thu, 31 Dec 2009 10:43:26 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/284.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2009/12/31/some-database-modification-tests.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/284.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
