<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-645031315867409681</id><updated>2011-11-27T16:41:05.097-08:00</updated><category term='MS SQL programming'/><category term='Android ADT14'/><category term='datetime sql datediff'/><category term='Hosting'/><category term='android training'/><category term='FREE'/><category term='ruby on rails as.net mvc'/><category term='SQL DELETE MERGE ORDER TOP  SQLSERVER  2008 database'/><category term='git android'/><category term='android pdf render java'/><category term='T-SQL Transaction LOCKS'/><category term='php eclipse zend'/><category term='android emulator apk'/><title type='text'>NotNullOrEmpty</title><subtitle type='html'>My daily notes about SQL, ASP .NET, MVC, Javascript, Php
,C++, and interesting things about programming.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-2352982445377426539</id><published>2011-11-13T18:16:00.000-08:00</published><updated>2011-11-13T18:16:32.744-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='android training'/><title type='text'>Android Training videos</title><content type='html'>These are the best Android training videos i have found so far:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://marakana.com/techtv/android_bootcamp_screencast_series.html"&gt;http://marakana.com/techtv/android_bootcamp_screencast_series.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, sans-serif;"&gt;These videos come from Marakana's 5-Day&amp;nbsp;&lt;/span&gt;&lt;a href="http://marakana.com/training/android/android_bootcamp.html" rel="nofollow" style="background-color: white; color: #333333; font-family: Verdana, sans-serif;"&gt;Android Bootcamp Training Course&lt;/a&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, sans-serif;"&gt;that&amp;nbsp;&lt;/span&gt;&lt;a href="http://marakana.com/expert/marko_gargenta,2.html" rel="nofollow" style="background-color: white; color: #333333; font-family: Verdana, sans-serif;"&gt;Marko Gargenta&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Verdana, sans-serif;"&gt;&amp;nbsp;taught in San Jose, CA earlier this year.&amp;nbsp;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-2352982445377426539?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/2352982445377426539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2011/11/android-training-videos.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/2352982445377426539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/2352982445377426539'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2011/11/android-training-videos.html' title='Android Training videos'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-6727719092982982108</id><published>2011-11-09T08:01:00.000-08:00</published><updated>2011-11-09T08:01:05.498-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='android emulator apk'/><title type='text'>Installing APk file into your emulator</title><content type='html'>You can use File explorer view in Eclipse to drag files there to install into Android.&lt;br /&gt;&lt;br /&gt;If you dont want to do it with Eclipse, you can do it in command line. You need to use "adb.exe" to do that. First add "...android-sdk/platform-tools/ to your path from advanced computer settings, so you can call adb from command line.&lt;br /&gt;&lt;br /&gt;Type "cmd" add search or run screen to launch command editor. If you have the path to adb, you can call that. Start the service: adb start-server&lt;br /&gt;&lt;br /&gt;If you see some error, you may need to manually delete old running adb.exe from your task manager.&lt;br /&gt;&lt;br /&gt;To install file after adb daemon running, you can type "adb install C:\yourfolder\yourfile.apk". If you previously installed this, it does not replace the old app. You need to delete that from emulator. You can use menu options to go to settings-&amp;gt;apps&amp;gt;your app-&amp;gt;uninstall.&lt;br /&gt;&lt;br /&gt;Hope, this helps you to use android emulator&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-6727719092982982108?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/6727719092982982108/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2011/11/installing-apk-file-into-your-emulator.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/6727719092982982108'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/6727719092982982108'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2011/11/installing-apk-file-into-your-emulator.html' title='Installing APk file into your emulator'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-6308209744471079628</id><published>2011-11-04T19:30:00.000-07:00</published><updated>2011-11-09T07:55:08.781-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='android pdf render java'/><title type='text'>Rendering pdf in android app</title><content type='html'>I was expecting this to be easy, but it got some complications. Android does not have native rendering for pdf,so you have different options. I decided to load the pdf in async task and then open the available pdf application. One nice feature with the Android framework is "the intents". You can launch application from another application with those intents. They have very nice way of managing different instances of same app. You can read more about this &lt;a href="http://developer.android.com/guide/topics/intents/intents-filters.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;You need to set manifest file first to enable file permissions.&lt;br /&gt;&lt;br /&gt;Here is my AndroidManifest.xml:&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #f1f0f0; color: black;"&gt;&lt;span style="color: #004a43;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #400000; font-weight: bold;"&gt;xml&lt;/span&gt;&lt;span style="color: #004a43;"&gt; &lt;/span&gt;&lt;span style="color: #074726;"&gt;version&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #007d45;"&gt;1.0&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #004a43;"&gt; &lt;/span&gt;&lt;span style="color: #074726;"&gt;encoding&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;utf-8&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #004a43;"&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;manifest&lt;/span&gt; &lt;span style="color: #00dddd;"&gt;xmlns&lt;/span&gt;&lt;span style="color: #806030;"&gt;:&lt;/span&gt;&lt;span style="color: #074726;"&gt;android&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #00dddd;"&gt;http&lt;/span&gt;&lt;span style="color: #806030;"&gt;:&lt;/span&gt;&lt;span style="color: #400000; font-weight: bold;"&gt;//&lt;/span&gt;&lt;span style="color: #5555dd;"&gt;schemas.android.com&lt;/span&gt;&lt;span style="color: #40015a;"&gt;/apk/res/android&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #074726;"&gt;package&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;com.android.demo&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #074726;"&gt;android:versionCode&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;1&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #074726;"&gt;android:versionName&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;1.0&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;uses-sdk&lt;/span&gt; &lt;span style="color: #074726;"&gt;android:minSdkVersion&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;14&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;application&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #074726;"&gt;android:icon&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;@drawable/ic_launcher&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #074726;"&gt;android:label&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;@string/app_name&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;activity&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #074726;"&gt;android:label&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;@string/app_name&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #074726;"&gt;android:name&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;.PdfprintdemoActivity&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;intent-filter&lt;/span&gt; &lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;action&lt;/span&gt; &lt;span style="color: #074726;"&gt;android:name&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;android.intent.action.MAIN&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;category&lt;/span&gt; &lt;span style="color: #074726;"&gt;android:name&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;android.intent.category.LAUNCHER&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;intent-filter&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;activity&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;application&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;uses-permission&lt;/span&gt; &lt;span style="color: #074726;"&gt;android:name&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;android.permission.WRITE_EXTERNAL_STORAGE&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;uses-permission&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;uses-permission&lt;/span&gt; &lt;span style="color: #074726;"&gt;android:name&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;android.permission.INTERNET&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;uses-permission&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;uses-permission&lt;/span&gt; &lt;span style="color: #074726;"&gt;android:name&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;android.permission.ACCESS_NETWORK_STATE&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;uses-permission&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;uses-permission&lt;/span&gt; &lt;span style="color: #074726;"&gt;android:name&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt;&lt;span style="color: #e60000;"&gt;android.permission.READ_PHONE_STATE&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"&lt;/span&gt; &lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;uses-permission&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;manifest&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I put everything inside one activity to make this example simple. There are some important elements that need to be explained.&lt;br /&gt;&lt;br /&gt;OnCreate method: It calls this method when creating the view. You should call the base method first then do your overrides.&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #f1f0f0; color: black;"&gt;&lt;span style="color: #3f5fbf;"&gt;/** Called when the activity is first created. */&lt;/span&gt;&lt;br /&gt;    @Override&lt;br /&gt;    &lt;span style="color: #400000; font-weight: bold;"&gt;public&lt;/span&gt; void onCreate(Bundle savedInstanceState) &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #c34e00;"&gt;//call base&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #400000; font-weight: bold;"&gt;super&lt;/span&gt;&lt;span style="color: #806030;"&gt;.&lt;/span&gt;onCreate&lt;span style="color: #806030;"&gt;(&lt;/span&gt;savedInstanceState&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #c34e00;"&gt;//set layout main.xml to be layout for this activity&lt;/span&gt;&lt;br /&gt;        setContentView&lt;span style="color: #806030;"&gt;(&lt;/span&gt;R&lt;span style="color: #806030;"&gt;.&lt;/span&gt;layout&lt;span style="color: #806030;"&gt;.&lt;/span&gt;main&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #c34e00;"&gt;//create references to the controls&lt;/span&gt;&lt;br /&gt;        startBtn &lt;span style="color: #806030;"&gt;=&lt;/span&gt; &lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #800040;"&gt;Button&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt; findViewById&lt;span style="color: #806030;"&gt;(&lt;/span&gt;R&lt;span style="color: #806030;"&gt;.&lt;/span&gt;id&lt;span style="color: #806030;"&gt;.&lt;/span&gt;startBtn&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #c34e00;"&gt;//attach listener in code or you can do that in layout file.&lt;/span&gt;&lt;br /&gt;        startBtn&lt;span style="color: #806030;"&gt;.&lt;/span&gt;setOnClickListener&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #400000; font-weight: bold;"&gt;new&lt;/span&gt; OnClickListener&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt; &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #400000; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: #800040;"&gt;void&lt;/span&gt; onClick&lt;span style="color: #806030;"&gt;(&lt;/span&gt;View v&lt;span style="color: #806030;"&gt;)&lt;/span&gt; &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;                startDownload&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;         &lt;br /&gt;    &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background-attachment: initial; background-clip: initial; background-color: #f1f0f0; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I used Async task to handle the download. It helps you to performasynchronous work on your user interface without halting the UI. You don't needto handle threads by yourself.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;doInBackground() executes automatically on a worker thread if you call "execute" method from this class.&amp;nbsp;&lt;/li&gt;&lt;li&gt;onPreExecute(), onPostExecute(), onProgressUpdate() are all invoked on the UI thread.&amp;nbsp;&lt;/li&gt;&lt;li&gt;You can set the return value from the "doInBackround()" as input to onPostExecute()&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;You can access publishProgress() from "doInBackround()" method to call "onProgressUpdate()"&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;We are setting the dialog at onPreExecute():&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #f1f0f0; color: black;"&gt;@Override&lt;br /&gt;        &lt;span style="color: #400000; font-weight: bold;"&gt;protected&lt;/span&gt; void onPreExecute() &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #400000; font-weight: bold;"&gt;super&lt;/span&gt;&lt;span style="color: #806030;"&gt;.&lt;/span&gt;onPreExecute&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            showDialog&lt;span style="color: #806030;"&gt;(&lt;/span&gt;DIALOG_DOWNLOAD_PROGRESS&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #c34e00;"&gt;//do actual download&lt;/span&gt;&lt;br /&gt;        @Override&lt;br /&gt;        &lt;span style="color: #400000; font-weight: bold;"&gt;protected&lt;/span&gt; String doInBackground(String... aurl) &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #800040;"&gt;int&lt;/span&gt; count&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #800040;"&gt;String&lt;/span&gt; fullpath &lt;span style="color: #806030;"&gt;=&lt;/span&gt; &lt;span style="color: #e60000;"&gt;""&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #400000; font-weight: bold;"&gt;try&lt;/span&gt; &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #800040;"&gt;URL&lt;/span&gt; url &lt;span style="color: #806030;"&gt;=&lt;/span&gt; &lt;span style="color: #400000; font-weight: bold;"&gt;new&lt;/span&gt; &lt;span style="color: #800040;"&gt;URL&lt;/span&gt;&lt;span style="color: #806030;"&gt;(&lt;/span&gt;aurl&lt;span style="color: #806030;"&gt;[&lt;/span&gt;&lt;span style="color: #c00000;"&gt;0&lt;/span&gt;&lt;span style="color: #806030;"&gt;]&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #800040;"&gt;URLConnection&lt;/span&gt; conexion &lt;span style="color: #806030;"&gt;=&lt;/span&gt; url&lt;span style="color: #806030;"&gt;.&lt;/span&gt;openConnection&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                conexion&lt;span style="color: #806030;"&gt;.&lt;/span&gt;connect&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #800040;"&gt;int&lt;/span&gt; lenghtOfFile &lt;span style="color: #806030;"&gt;=&lt;/span&gt; conexion&lt;span style="color: #806030;"&gt;.&lt;/span&gt;getContentLength&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                Log&lt;span style="color: #806030;"&gt;.&lt;/span&gt;d&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"ANDRO_ASYNC"&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt; &lt;span style="color: #e60000;"&gt;"Lenght of file: "&lt;/span&gt; &lt;span style="color: #806030;"&gt;+&lt;/span&gt; lenghtOfFile&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #c34e00;"&gt;//Get directory&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #800040;"&gt;File&lt;/span&gt; root &lt;span style="color: #806030;"&gt;=&lt;/span&gt; Environment&lt;span style="color: #806030;"&gt;.&lt;/span&gt;getExternalStorageDirectory&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #800040;"&gt;InputStream&lt;/span&gt; input &lt;span style="color: #806030;"&gt;=&lt;/span&gt; &lt;span style="color: #400000; font-weight: bold;"&gt;new&lt;/span&gt; &lt;span style="color: #800040;"&gt;BufferedInputStream&lt;/span&gt;&lt;span style="color: #806030;"&gt;(&lt;/span&gt;url&lt;span style="color: #806030;"&gt;.&lt;/span&gt;openStream&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #800040;"&gt;OutputStream&lt;/span&gt; output &lt;span style="color: #806030;"&gt;=&lt;/span&gt;  &lt;span style="color: #400000; font-weight: bold;"&gt;new&lt;/span&gt; &lt;span style="color: #800040;"&gt;FileOutputStream&lt;/span&gt;&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #400000; font-weight: bold;"&gt;new&lt;/span&gt; &lt;span style="color: #800040;"&gt;File&lt;/span&gt;&lt;span style="color: #806030;"&gt;(&lt;/span&gt;root&lt;span style="color: #806030;"&gt;,&lt;/span&gt;&lt;br /&gt;                        aurl&lt;span style="color: #806030;"&gt;[&lt;/span&gt;&lt;span style="color: #c00000;"&gt;1&lt;/span&gt;&lt;span style="color: #806030;"&gt;]&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #800040;"&gt;byte&lt;/span&gt; data&lt;span style="color: #806030;"&gt;[&lt;/span&gt;&lt;span style="color: #806030;"&gt;]&lt;/span&gt; &lt;span style="color: #806030;"&gt;=&lt;/span&gt; &lt;span style="color: #400000; font-weight: bold;"&gt;new&lt;/span&gt; &lt;span style="color: #800040;"&gt;byte&lt;/span&gt;&lt;span style="color: #806030;"&gt;[&lt;/span&gt;&lt;span style="color: #c00000;"&gt;1024&lt;/span&gt;&lt;span style="color: #806030;"&gt;]&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                fullpath &lt;span style="color: #806030;"&gt;=&lt;/span&gt; root&lt;span style="color: #806030;"&gt;.&lt;/span&gt;getAbsolutePath&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;+&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"/"&lt;/span&gt;&lt;span style="color: #806030;"&gt;+&lt;/span&gt;aurl&lt;span style="color: #806030;"&gt;[&lt;/span&gt;&lt;span style="color: #c00000;"&gt;1&lt;/span&gt;&lt;span style="color: #806030;"&gt;]&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                Log&lt;span style="color: #806030;"&gt;.&lt;/span&gt;d&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"ANDRO_ASYNC"&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"path:"&lt;/span&gt;&lt;span style="color: #806030;"&gt;+&lt;/span&gt;fullpath&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #800040;"&gt;long&lt;/span&gt; total &lt;span style="color: #806030;"&gt;=&lt;/span&gt; &lt;span style="color: #c00000;"&gt;0&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #400000; font-weight: bold;"&gt;while&lt;/span&gt; &lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;(&lt;/span&gt;count &lt;span style="color: #806030;"&gt;=&lt;/span&gt; input&lt;span style="color: #806030;"&gt;.&lt;/span&gt;read&lt;span style="color: #806030;"&gt;(&lt;/span&gt;data&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt; &lt;span style="color: #806030;"&gt;!&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt; &lt;span style="color: #806030;"&gt;-&lt;/span&gt;&lt;span style="color: #c00000;"&gt;1&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt; &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;                    total &lt;span style="color: #806030;"&gt;+&lt;/span&gt;&lt;span style="color: #806030;"&gt;=&lt;/span&gt; count&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                    publishProgress&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;""&lt;/span&gt; &lt;span style="color: #806030;"&gt;+&lt;/span&gt; &lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #800040;"&gt;int&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt; &lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;(&lt;/span&gt;total &lt;span style="color: #806030;"&gt;*&lt;/span&gt; &lt;span style="color: #c00000;"&gt;100&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt; &lt;span style="color: #806030;"&gt;/&lt;/span&gt; lenghtOfFile&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                    output&lt;span style="color: #806030;"&gt;.&lt;/span&gt;write&lt;span style="color: #806030;"&gt;(&lt;/span&gt;data&lt;span style="color: #806030;"&gt;,&lt;/span&gt; &lt;span style="color: #c00000;"&gt;0&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt; count&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;                output&lt;span style="color: #806030;"&gt;.&lt;/span&gt;flush&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                output&lt;span style="color: #806030;"&gt;.&lt;/span&gt;close&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                input&lt;span style="color: #806030;"&gt;.&lt;/span&gt;close&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                Log&lt;span style="color: #806030;"&gt;.&lt;/span&gt;d&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"ANDRO_ASYNC"&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt; &lt;span style="color: #e60000;"&gt;"File closed1: "&lt;/span&gt; &lt;span style="color: #806030;"&gt;+&lt;/span&gt; lenghtOfFile&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #806030;"&gt;}&lt;/span&gt; &lt;span style="color: #400000; font-weight: bold;"&gt;catch&lt;/span&gt; &lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #800040;"&gt;Exception&lt;/span&gt; e&lt;span style="color: #806030;"&gt;)&lt;/span&gt; &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;                Log&lt;span style="color: #806030;"&gt;.&lt;/span&gt;d&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"error"&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt;e&lt;span style="color: #806030;"&gt;.&lt;/span&gt;getMessage&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #400000; font-weight: bold;"&gt;return&lt;/span&gt; fullpath&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #f1f0f0; color: black;"&gt;&lt;span style="color: #c34e00;"&gt;/*We use this method to update progress bar*/&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #400000; font-weight: bold;"&gt;protected&lt;/span&gt; void onProgressUpdate(String... progress) &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;            Log&lt;span style="color: #806030;"&gt;.&lt;/span&gt;d&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"ANDRO_ASYNC"&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt; progress&lt;span style="color: #806030;"&gt;[&lt;/span&gt;&lt;span style="color: #c00000;"&gt;0&lt;/span&gt;&lt;span style="color: #806030;"&gt;]&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            mProgressDialogWindow&lt;span style="color: #806030;"&gt;.&lt;/span&gt;setProgress&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #800040;"&gt;Integer&lt;/span&gt;&lt;span style="color: #806030;"&gt;.&lt;/span&gt;parseInt&lt;span style="color: #806030;"&gt;(&lt;/span&gt;progress&lt;span style="color: #806030;"&gt;[&lt;/span&gt;&lt;span style="color: #c00000;"&gt;0&lt;/span&gt;&lt;span style="color: #806030;"&gt;]&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;        &lt;span style="color: #c34e00;"&gt;/* This method takes the return param from doinbackground call as input*/&lt;/span&gt;&lt;br /&gt;        @Override&lt;br /&gt;        &lt;span style="color: #400000; font-weight: bold;"&gt;protected&lt;/span&gt; void onPostExecute(String linkname) &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;            mProgressDialogWindow&lt;span style="color: #806030;"&gt;.&lt;/span&gt;setMessage&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"Finished"&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            dismissDialog&lt;span style="color: #806030;"&gt;(&lt;/span&gt;DIALOG_DOWNLOAD_PROGRESS&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            Log&lt;span style="color: #806030;"&gt;.&lt;/span&gt;d&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"onPostExecute"&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"Send:"&lt;/span&gt;&lt;span style="color: #806030;"&gt;+&lt;/span&gt;linkname&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            OpenFile&lt;span style="color: #806030;"&gt;(&lt;/span&gt;linkname&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;        &lt;span style="color: #c34e00;"&gt;/*We are firing intent to open this file with avaialble pdf viewer*/&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #400000; font-weight: bold;"&gt;protected&lt;/span&gt; void OpenFile(String linkname)&lt;br /&gt;        &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #800040;"&gt;File&lt;/span&gt; file &lt;span style="color: #806030;"&gt;=&lt;/span&gt; &lt;span style="color: #400000; font-weight: bold;"&gt;new&lt;/span&gt; &lt;span style="color: #800040;"&gt;File&lt;/span&gt;&lt;span style="color: #806030;"&gt;(&lt;/span&gt;linkname&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #400000; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #806030;"&gt;(&lt;/span&gt;file&lt;span style="color: #806030;"&gt;.&lt;/span&gt;exists&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt; &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;                Log&lt;span style="color: #806030;"&gt;.&lt;/span&gt;d&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"OpenFile"&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"Exists:"&lt;/span&gt;&lt;span style="color: #806030;"&gt;+&lt;/span&gt;linkname&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                Uri path &lt;span style="color: #806030;"&gt;=&lt;/span&gt; Uri&lt;span style="color: #806030;"&gt;.&lt;/span&gt;fromFile&lt;span style="color: #806030;"&gt;(&lt;/span&gt;file&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                Intent intent &lt;span style="color: #806030;"&gt;=&lt;/span&gt; &lt;span style="color: #400000; font-weight: bold;"&gt;new&lt;/span&gt; Intent&lt;span style="color: #806030;"&gt;(&lt;/span&gt;Intent&lt;span style="color: #806030;"&gt;.&lt;/span&gt;ACTION_VIEW&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                intent&lt;span style="color: #806030;"&gt;.&lt;/span&gt;setDataAndType&lt;span style="color: #806030;"&gt;(&lt;/span&gt;path&lt;span style="color: #806030;"&gt;,&lt;/span&gt; &lt;span style="color: #e60000;"&gt;"application/pdf"&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                intent&lt;span style="color: #806030;"&gt;.&lt;/span&gt;setFlags&lt;span style="color: #806030;"&gt;(&lt;/span&gt;Intent&lt;span style="color: #806030;"&gt;.&lt;/span&gt;FLAG_ACTIVITY_CLEAR_TOP&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #400000; font-weight: bold;"&gt;try&lt;/span&gt; &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;                    startActivity&lt;span style="color: #806030;"&gt;(&lt;/span&gt;intent&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #806030;"&gt;}&lt;/span&gt; &lt;br /&gt;                &lt;span style="color: #400000; font-weight: bold;"&gt;catch&lt;/span&gt; &lt;span style="color: #806030;"&gt;(&lt;/span&gt;ActivityNotFoundException e&lt;span style="color: #806030;"&gt;)&lt;/span&gt; &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;                    Toast&lt;span style="color: #806030;"&gt;.&lt;/span&gt;makeText&lt;span style="color: #806030;"&gt;(&lt;/span&gt;PdfprintdemoActivity&lt;span style="color: #806030;"&gt;.&lt;/span&gt;&lt;span style="color: #400000; font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt; &lt;br /&gt;                        &lt;span style="color: #e60000;"&gt;"No Application Available to View PDF"&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt; &lt;br /&gt;                        Toast&lt;span style="color: #806030;"&gt;.&lt;/span&gt;LENGTH_SHORT&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;.&lt;/span&gt;show&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;span style="color: #400000; font-weight: bold;"&gt;else&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #806030;"&gt;{&lt;/span&gt;&lt;br /&gt;                Log&lt;span style="color: #806030;"&gt;.&lt;/span&gt;d&lt;span style="color: #806030;"&gt;(&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"OpenFile"&lt;/span&gt;&lt;span style="color: #806030;"&gt;,&lt;/span&gt;&lt;span style="color: #e60000;"&gt;"DOES NOT Exists:"&lt;/span&gt;&lt;span style="color: #806030;"&gt;+&lt;/span&gt;linkname&lt;span style="color: #806030;"&gt;)&lt;/span&gt;&lt;span style="color: #806030;"&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #806030;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-6308209744471079628?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/6308209744471079628/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2011/11/rendering-pdf-in-android-app.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/6308209744471079628'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/6308209744471079628'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2011/11/rendering-pdf-in-android-app.html' title='Rendering pdf in android app'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-995791008848506825</id><published>2011-10-30T19:23:00.000-07:00</published><updated>2011-10-30T19:30:38.920-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='git android'/><title type='text'>Gitignore settings for Android</title><content type='html'>&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre class="default prettyprint" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"&gt;&lt;code style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="com" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: grey; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;# ignore built application files&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;*.&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;apk&lt;/span&gt;&lt;span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;*.&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;ap_&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre class="default prettyprint" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"&gt;&lt;code style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="com" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: grey; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;# Java class files&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;*.&lt;/span&gt;&lt;span class="kwd" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: darkblue; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;class&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"&gt;&lt;pre class="default prettyprint" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"&gt;&lt;code style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="com" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: grey; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;# VM files&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;*.&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;dex&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="com" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: grey; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;# dont need generated files&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;br /&gt;bin&lt;/span&gt;&lt;span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;/&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;br /&gt;gen&lt;/span&gt;&lt;span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;/&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="com" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: grey; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;# Local configuration files&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="kwd" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: darkblue; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;local&lt;/span&gt;&lt;span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;.&lt;/span&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;properties&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class="default prettyprint" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"&gt;&lt;code style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: black; font-size: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;#You can copy those into gitignore.txt and then save as ".gitignore" in "all files format". &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-995791008848506825?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/995791008848506825/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2011/10/gitignore-settings-for-android.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/995791008848506825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/995791008848506825'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2011/10/gitignore-settings-for-android.html' title='Gitignore settings for Android'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-4933644202875199352</id><published>2011-10-24T18:58:00.000-07:00</published><updated>2011-10-24T18:58:16.809-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby on rails as.net mvc'/><title type='text'>Ruby on Rails 3.0</title><content type='html'>I have created&lt;a href="http://omercansizoglu.com/"&gt; a webpage&lt;/a&gt; in Ruby on Rails after going through all those server setup at slicehost.com and all those plugins. I kinda like the CMS editor, but don't like plugin hell!&lt;br /&gt;&lt;br /&gt;I installed one file management plugin to upload css and js files,but it was so stupid to cut off after some characters. After checking their code, i realized that they were using "Get" method to send data. I learned hard way that you should not trust those weird plugins they got. They got so many different versions and it needs to be compatible. Besides all those, I really like the scaffolding, conventions in modelling, and different view engine options. It is definitely ahead of the current Asp.net MVC 3 or 4 with all those features. You may know that recent asp.net mvc features and code sharing with nuget packages are copy of RoR. You can do scaffolding with T4 templates and do the data modeling&amp;nbsp;style&amp;nbsp;coding with new Entity framework code first approach. They are still weak on the data migration &amp;nbsp;part, but it is coming very strong.&lt;br /&gt;&lt;br /&gt;If you setup a server for your RoR project before, you may know all different options and little things to do. If you have limited memory on your slice, it takes some time to restart worker threads after inactivity period. They are not very efficient. I did bunch different things to make it work. Good thing is you can find everything about to start a server from scratch. You can check articles at Slicehost.com for different server options.&lt;br /&gt;&lt;br /&gt;Anyway, What do you think about Ruby on Rails and Asp.Net MVC?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-4933644202875199352?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/4933644202875199352/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2011/10/ruby-on-rails-30.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/4933644202875199352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/4933644202875199352'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2011/10/ruby-on-rails-30.html' title='Ruby on Rails 3.0'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-3610045147378194693</id><published>2011-10-24T18:47:00.000-07:00</published><updated>2011-10-30T19:27:26.356-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Android ADT14'/><title type='text'>Android  ADT 14 and Android Unknown Command 'crunch'</title><content type='html'>I just setup a sample project to check out android development, but got weird error related to 'crunch' command. How is that possible with fresh sdk tools and all included eclipse package setup. It was very&amp;nbsp;discouraging, but i decide to figure out a way to at least run some demos and see "hello world" in different platform versions.&lt;br /&gt;&lt;br /&gt;Solution: You need to install this ADT 14. Yes. you need to uninstall all those old Android SDK and try again:)&lt;br /&gt;I checked all necesary items in the Eclipse window. After downloading all those libraries, you should setup the SDK directory for android.&lt;br /&gt;&lt;br /&gt;At the end, you should see references to correct version of ADT. "Hello world" will work fine now. You can create new projects from sample Android apps. It really helps to learn overall design.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-3610045147378194693?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/3610045147378194693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2011/10/android-adt-14-and-weird-problems.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/3610045147378194693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/3610045147378194693'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2011/10/android-adt-14-and-weird-problems.html' title='Android  ADT 14 and Android Unknown Command &apos;crunch&apos;'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-7721338439222452625</id><published>2010-11-25T06:24:00.000-08:00</published><updated>2010-11-25T06:24:18.072-08:00</updated><title type='text'>How to create shortcut for namespaces in your view files for ASP?</title><content type='html'>You can import namespaces at the beginning of the page and reference them directly.&lt;br /&gt;&lt;br /&gt; &lt;%@ Import Namespace="myapp.Controllers" %&gt;&lt;br /&gt;&lt;br /&gt;If you have a Product controller in myapp, you can reference this directly without writing myapp.Controllers.Product.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-7721338439222452625?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/7721338439222452625/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/11/how-to-create-shortcut-for-namespaces.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/7721338439222452625'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/7721338439222452625'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/11/how-to-create-shortcut-for-namespaces.html' title='How to create shortcut for namespaces in your view files for ASP?'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-2765475475782147722</id><published>2010-11-19T11:21:00.000-08:00</published><updated>2010-11-19T11:21:25.072-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MS SQL programming'/><title type='text'>How to trigger event for Truncate action in MS SQL</title><content type='html'>NOTE:&lt;br /&gt;&lt;br /&gt;?????&lt;br /&gt;I guess it is not possible to trigger event for Truncate,but prevent it.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;From msdn:&lt;/b&gt;&lt;br /&gt;TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions. We can prevent truncate action,if we create a view WITH SCHEMABINDING.&lt;br /&gt;&lt;br /&gt;If we don't use truncate on the application level, we will be dealing with only delete command. It is easy to prevent that with Instead Of Trigger.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-2765475475782147722?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/2765475475782147722/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/11/how-to-trigger-event-for-truncate.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/2765475475782147722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/2765475475782147722'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/11/how-to-trigger-event-for-truncate.html' title='How to trigger event for Truncate action in MS SQL'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-5176811551150004146</id><published>2010-10-29T06:57:00.000-07:00</published><updated>2010-12-10T08:46:38.702-08:00</updated><title type='text'>ASP MVC IIS not running</title><content type='html'>Hey,&lt;br /&gt;&lt;br /&gt;&amp;nbsp;I had the same problem on IIS 7.5 with MVC 1. I fixed the problem and listed some steps here:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_mHCrhAzxcpY/TMrK4yMHJ7I/AAAAAAAAArw/xdfRD30LIEs/s1600/iis_addons.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="179" src="http://3.bp.blogspot.com/_mHCrhAzxcpY/TMrK4yMHJ7I/AAAAAAAAArw/xdfRD30LIEs/s320/iis_addons.jpg" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Figure-1:Install other IIS options&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Read other normal IIS config steps&lt;/li&gt;&lt;ol&gt;&lt;li&gt;If you dont see Asp.Net tab in config option, you need to register asp.net&amp;nbsp;&lt;/li&gt;&lt;ol&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;"&gt;%windir%\Microsoft.NET\&lt;/span&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;wbr&gt;&lt;/wbr&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;"&gt;Framework\v2.0.50727\aspnet_&lt;/span&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;"&gt;&lt;wbr&gt;&lt;/wbr&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px;"&gt;regiis.exe -i&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/ol&gt;&lt;li&gt;You need to check add-on features to install some other components to make IIS work. Installing them solves most of the problem. Redirect is off by default. Go to control panel -&amp;gt;programs-&amp;gt; Windows components part as show on Figure-1. If you don't see your aspx pages, it might be missing .net integration.&amp;nbsp;&lt;/li&gt;&lt;li&gt;Create your app and add simple html, asp pages for testing&lt;/li&gt;&lt;ol&gt;&lt;li&gt;if it is showing default app, you need to remove that application&lt;/li&gt;&lt;li&gt;You may need to start and stop application to make it work&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;Change app pool identity to local system and give permissions at your database to access your tables for this user&lt;/li&gt;&lt;li&gt;Allow all users for .net authorization&lt;/li&gt;&lt;li&gt;It will work after these steps. If not check these:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;You may need to check connection strings to make sure you are connecting to the right sql instance&lt;/li&gt;&lt;li&gt;Permission problem: You may need to give permission to web folders for application identity. If you change that to something else, add that user to list and give permissions.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-5176811551150004146?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/5176811551150004146/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/10/asp-mvc-iis-not-running.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/5176811551150004146'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/5176811551150004146'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/10/asp-mvc-iis-not-running.html' title='ASP MVC IIS not running'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_mHCrhAzxcpY/TMrK4yMHJ7I/AAAAAAAAArw/xdfRD30LIEs/s72-c/iis_addons.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-4671738426169013132</id><published>2010-08-07T20:09:00.000-07:00</published><updated>2010-08-07T20:09:27.649-07:00</updated><title type='text'>notes about xml processing in sql server</title><content type='html'>----working with xml data&lt;br /&gt;--retrieving relational data as xml&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--passing data a xml&lt;br /&gt;&lt;br /&gt;--storing and querying actual&lt;br /&gt;use AdventureWorks;&lt;br /&gt;&lt;br /&gt;select&lt;br /&gt;c.CustomerID,&lt;br /&gt;c.AccountNumber,&lt;br /&gt;c.CustomerType&lt;br /&gt;&lt;br /&gt;from sales.Customer as c&lt;br /&gt;where c.CustomerID in (1,2) ;&lt;br /&gt;&lt;br /&gt;select soh.CustomerID,&lt;br /&gt;soh.SalesOrderID,&lt;br /&gt;soh.OrderDate,&lt;br /&gt;soh.ShipDate&lt;br /&gt;from Sales.SalesOrderHeader as soh&lt;br /&gt;where soh.CustomerID in (1,2);&lt;br /&gt;&lt;br /&gt;--instead use join query&lt;br /&gt;select c.customerid , c.accountnumber, c.customertype,&lt;br /&gt;soh.SalesPersonID, soh.OrderDate, soh.ShipDate&lt;br /&gt;&lt;br /&gt;from&lt;br /&gt;Sales.Customer as c left outer join&lt;br /&gt;&lt;br /&gt;Sales.SalesOrderHeader as soh on soh.CustomerID = c.CustomerID&lt;br /&gt;where c.CustomerID in (1,2)&lt;br /&gt;&lt;br /&gt;--xml&lt;br /&gt;select c.customerid as "@Id"&lt;br /&gt;, c.accountnumber as "@AccountNumber"&lt;br /&gt;, c.customertype as "@Type"&lt;br /&gt;,(&lt;br /&gt;SELECT&lt;br /&gt;soh.SalesOrderID as "@Id"&lt;br /&gt;,soh.OrderDate as "@OrderDate"&lt;br /&gt;, soh.ShipDate as "@ShipDate"&lt;br /&gt;&amp;nbsp;from Sales.SalesOrderHeader as soh&lt;br /&gt;&amp;nbsp;where soh.CustomerID = c.CustomerID&lt;br /&gt;&amp;nbsp;for XML Path('Order') , TYPE&lt;br /&gt;) as "Orders"&lt;br /&gt;from&lt;br /&gt;Sales.Customer as c &amp;nbsp;&lt;br /&gt;where c.CustomerID in (1,2)&lt;br /&gt;FOR XML PATH('Customer'), ROOT('Customers');&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;USe AdventureWorks;&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;select&lt;br /&gt;p.ProductID as "@Id",&lt;br /&gt;p.Name as "Info/@Name",&lt;br /&gt;p.ListPrice as "Info/@Listprice",&lt;br /&gt;(&lt;br /&gt;select&lt;br /&gt;sod.SalesOrderID as "@Orderid",&lt;br /&gt;sod.OrderQty as "@QTY",&lt;br /&gt;soh.OrderDate as "@date",&lt;br /&gt;soh.CustomerID as "@customerid"&lt;br /&gt;&lt;br /&gt;from Sales.SalesOrderHeader soh&lt;br /&gt;inner join Sales.SalesOrderDetail as sod&lt;br /&gt;on sod.SalesOrderID = soh.SalesOrderID&lt;br /&gt;where sod.ProductID = p.ProductID&lt;br /&gt;for XML path('Ordersub'), TYPE&lt;br /&gt;)&lt;br /&gt;from Production.Product as p&lt;br /&gt;where p.ProductID = 707&lt;br /&gt;for xml path('Product');&lt;br /&gt;&lt;br /&gt;---master order and details&lt;br /&gt;select&lt;br /&gt;p.ProductID as "@Id",&lt;br /&gt;p.Name as "Info/@Name",&lt;br /&gt;p.ListPrice as "Info/@Listprice",&lt;br /&gt;(&lt;br /&gt;select&lt;br /&gt;sod.SalesOrderID as "@Orderid",&lt;br /&gt;sod.OrderQty as "@QTY",&lt;br /&gt;soh.OrderDate as "@date",&lt;br /&gt;soh.CustomerID as "@customerid"&lt;br /&gt;&lt;br /&gt;from Sales.SalesOrderHeader soh&lt;br /&gt;inner join Sales.SalesOrderDetail as sod&lt;br /&gt;on sod.SalesOrderID = soh.SalesOrderID&lt;br /&gt;where sod.ProductID = p.ProductID&lt;br /&gt;for XML path('Ordersub'), TYPE&lt;br /&gt;)&lt;br /&gt;from Sales.SalesOrderHeader soh&lt;br /&gt;where p.ProductID = 707&lt;br /&gt;for xml path('Product');&lt;br /&gt;&lt;br /&gt;--list top 10 orders with amount max&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;select &amp;nbsp;top 1&lt;br /&gt;sh.SalesOrderID as "@ID",&lt;br /&gt;sh.OrderDate as "@OrderDate",&lt;br /&gt;sh.ShipDate as "@ShipDate",&lt;br /&gt;sh.Status as "@Status",&lt;br /&gt;sh.CustomerID as "@CustomerID",&lt;br /&gt;sh.SalesPersonID as "@SalesPersonID",&lt;br /&gt;sh.Totaldue as "@TotalDue",&lt;br /&gt;(select top 5&lt;br /&gt;sod.ProductID,&lt;br /&gt;sod.OrderQty,&lt;br /&gt;sod.LineTotal&lt;br /&gt;from&lt;br /&gt;&amp;nbsp;Sales.SalesOrderDetail sod&lt;br /&gt;&amp;nbsp;where sod.SalesOrderID = sh.SalesOrderID&lt;br /&gt;&amp;nbsp;order by sod.LineTotal desc&lt;br /&gt;for XML path('Ordersub'), TYPE&lt;br /&gt;&amp;nbsp;)&lt;br /&gt;&amp;nbsp;from Sales.SalesOrderHeader sh &lt;br /&gt;&amp;nbsp;order by sh.TotalDue desc&lt;br /&gt;for xml path('Sales') ,root('SalesTop10')&lt;br /&gt;&lt;br /&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--read test&lt;br /&gt;Declare @myxml XML&lt;br /&gt;&lt;br /&gt;set @myxml = N'&lt;br /&gt;&lt;salestop10&gt;&lt;/salestop10&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;sales customerid="599" id="51131" orderdate="2003-07-01T00:00:00" salespersonid="281" shipdate="2003-07-08T00:00:00" status="5" totaldue="247913.9138"&gt;&lt;/sales&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;productid&gt;969&lt;/productid&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;orderqty&gt;21&lt;/orderqty&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;26159.208075&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;productid&gt;966&lt;/productid&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;orderqty&gt;16&lt;/orderqty&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;19930.825200&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;productid&gt;954&lt;/productid&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;orderqty&gt;16&lt;/orderqty&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;12206.438400&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;productid&gt;892&lt;/productid&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;orderqty&gt;23&lt;/orderqty&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;12064.488425&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;productid&gt;967&lt;/productid&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;orderqty&gt;6&lt;/orderqty&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;8582.652000&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&lt;br /&gt;';&lt;br /&gt;&lt;br /&gt;select @myxml.query('&lt;br /&gt;&lt;myresults&gt;&lt;/myresults&gt;&lt;br /&gt;{for $o in /SalesTop10/Sales/Ordersub&lt;br /&gt;&amp;nbsp;where &amp;nbsp;$o/OrderQty &amp;nbsp;&amp;gt; 16&lt;br /&gt;&amp;nbsp;return &amp;nbsp;&lt;best_match orderqty="{data( $o/OrderQty)}" productid="{data( $o/ProductID)}"&gt;&lt;/best_match&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;')&lt;br /&gt;&lt;br /&gt;/* output&lt;br /&gt;&lt;myresults&gt;&lt;/myresults&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;best_match orderqty="21" productid="969"&gt;&lt;/best_match&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;best_match orderqty="23" productid="892"&gt;&lt;/best_match&gt;&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;---all of them in properties&lt;br /&gt;select &amp;nbsp;top 1&lt;br /&gt;sh.SalesOrderID as "@ID",&lt;br /&gt;sh.OrderDate as "@OrderDate",&lt;br /&gt;sh.ShipDate as "@ShipDate",&lt;br /&gt;sh.Status as "@Status",&lt;br /&gt;sh.CustomerID as "@CustomerID",&lt;br /&gt;sh.SalesPersonID as "@SalesPersonID",&lt;br /&gt;sh.Totaldue as "@TotalDue",&lt;br /&gt;(select top 5&lt;br /&gt;sod.ProductID as "@ProductID",&lt;br /&gt;sod.OrderQty as "@QTY",&lt;br /&gt;sod.LineTotal as "LineTotal"&lt;br /&gt;from&lt;br /&gt;&amp;nbsp;Sales.SalesOrderDetail sod&lt;br /&gt;&amp;nbsp;where sod.SalesOrderID = sh.SalesOrderID&lt;br /&gt;&amp;nbsp;order by sod.LineTotal desc&lt;br /&gt;for XML path('Ordersub'), TYPE&lt;br /&gt;&amp;nbsp;)&lt;br /&gt;&amp;nbsp;from Sales.SalesOrderHeader sh &lt;br /&gt;&amp;nbsp;order by sh.TotalDue desc&lt;br /&gt;for xml path('Sales') ,root('SalesTop1')&lt;br /&gt;&lt;br /&gt;;&lt;br /&gt;&lt;br /&gt;declare @otherxml XML&lt;br /&gt;set @otherxml = N'&lt;br /&gt;&lt;salestop1&gt;&lt;/salestop1&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;sales customerid="599" id="51131" orderdate="2003-07-01T00:00:00" salespersonid="281" shipdate="2003-07-08T00:00:00" status="5" totaldue="247913.9138"&gt;&lt;/sales&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub productid="969" qty="21"&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;26159.208075&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub productid="966" qty="16"&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;19930.825200&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub productid="954" qty="16"&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;12206.438400&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub productid="892" qty="23"&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;12064.488425&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;ordersub productid="967" qty="6"&gt;&lt;/ordersub&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;linetotal&gt;8582.652000&lt;/linetotal&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&lt;br /&gt;';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;---reshape results with xquery&lt;br /&gt;&lt;br /&gt;SELECT (SELECT top 10 * FROM Sales.Customer as Customers FOR XML AUTO,type &amp;nbsp; ).query(&lt;br /&gt;'&lt;doc&gt;{&lt;/doc&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; for $c in /Customers&lt;br /&gt;&amp;nbsp;&amp;nbsp; return&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;person id="{data($c/@CustomerID)}"&gt;&lt;/person&gt;&lt;br /&gt;&amp;nbsp;}')&lt;br /&gt;&lt;br /&gt;&amp;nbsp;---&lt;br /&gt;&amp;nbsp;;&lt;br /&gt;&amp;nbsp;create schema TestXml;&lt;br /&gt;&amp;nbsp;go&lt;br /&gt;&lt;br /&gt;&amp;nbsp;create table TestXml.Messages&lt;br /&gt;&amp;nbsp;(&lt;br /&gt;&amp;nbsp;MessageID int identity primary key,&lt;br /&gt;&amp;nbsp;FromUser nvarchar(50) not null,&lt;br /&gt;&amp;nbsp;Message nvarchar(max) not null,&lt;br /&gt;&amp;nbsp;CreatedDateTime datetime2 not null default sysdatetime()&lt;br /&gt;&amp;nbsp;);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;--proc to insert data from xml input&lt;br /&gt;&lt;br /&gt;&amp;nbsp;create procedure TestXml.spMessageAddMany&lt;br /&gt;&amp;nbsp;@Message XML&lt;br /&gt;&amp;nbsp;as&lt;br /&gt;&amp;nbsp;Begin&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;set nocount on;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Insert TestXml.Messages (FromUser, Message)&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp;Select&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp; tab.col.value('@FromUser', 'NVARCHAR(50)'),&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp; tab.col.value('text()[1]', 'NVARCHAR(max)')&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp;from @Message.nodes('/Messages/Message') as tab(col);&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;---now insert some xml messages&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;EXEC TestXml.spMessageAddMany @Message = N'&lt;br /&gt;&lt;messages&gt;&lt;/messages&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;message fromuser="my dummy1"&gt;Naber nasil?&lt;/message&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;message fromuser="my dummy2"&gt;Naber nasil2?&lt;/message&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;message fromuser="my dummy2"&gt;Naber nasil3?&lt;/message&gt;&lt;br /&gt;';&lt;br /&gt;&lt;br /&gt;Select * from TestXml.Messages;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;--working with xml stored in xml variable or column&lt;br /&gt;EXIST METHOd&lt;br /&gt;&lt;br /&gt;select top 1 Demographics&lt;br /&gt;from Sales.Individual&lt;br /&gt;&lt;br /&gt;with xmlnamespaces(default&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;'http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey')&lt;br /&gt;select COUNT(*)&lt;br /&gt;from Sales.Individual&lt;br /&gt;where Demographics.exist(&lt;br /&gt;&amp;nbsp;'/IndividualSurvey/Occupation') = 1&lt;br /&gt;&lt;br /&gt;with xmlnamespaces(default&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;'http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey')&lt;br /&gt;select COUNT(*)&lt;br /&gt;from Sales.Individual&lt;br /&gt;where Demographics.exist(&lt;br /&gt;&amp;nbsp;'/IndividualSurvey/TotalPurchaseYTD[xs:decimal(.) &amp;gt; 8000]') = 1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;with xmlnamespaces(default&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;'http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey')&lt;br /&gt;select COUNT(*)&lt;br /&gt;from Sales.Individual&lt;br /&gt;where Demographics.exist(&lt;br /&gt;&amp;nbsp;'/IndividualSurvey/TotalPurchaseYTD[xs:decimal(.) &amp;gt; 8000]') = 1 &lt;br /&gt;&lt;br /&gt;&amp;nbsp;---Extract Properties from XML Variable&lt;br /&gt;DECLARE @xVar XML&lt;br /&gt;SET @xVar =&lt;br /&gt;'&lt;book genre="security" isbn="0-7356-1588-2" publicationdate="2002"&gt;&lt;/book&gt;&lt;br /&gt;&lt;br /&gt;&lt;author&gt;&lt;/author&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;first-name&gt;Michael&lt;/first-name&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;last-name&gt;Howard&lt;/last-name&gt;&lt;br /&gt;&lt;br /&gt;&lt;author&gt;&lt;/author&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;first-name&gt;David&lt;/first-name&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;last-name&gt;LeBlanc&lt;/last-name&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;subauthor&gt;&lt;/subauthor&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp;&lt;sub-first-name&gt;2David&lt;/sub-first-name&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp;&lt;sub-last-name&gt;2LeBlanc&lt;/sub-last-name&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp;&lt;sub-last-name&gt;3LeBlanc&lt;/sub-last-name&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;price&gt;39.99&lt;/price&gt;&lt;br /&gt;'&lt;br /&gt;&lt;br /&gt;SELECT nref.value('first-name[1]', 'nvarchar(50)') FirstName, --get first element [1]&lt;br /&gt;&amp;nbsp;&amp;nbsp; nref.value('last-name[1]', 'nvarchar(50)') LastName&lt;br /&gt;FROM &amp;nbsp; @xVar.nodes('//author') AS R(nref)&lt;br /&gt;WHERE &amp;nbsp;nref.exist('.[first-name != "David"]') = 1&lt;br /&gt;&lt;br /&gt;--value method&lt;br /&gt;&lt;br /&gt;with xmlnamespaces(default&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;'http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey')&lt;br /&gt;select SUM(demographics.value('count(/IndividualSurvey)', 'INT')) AS NumberofISurveys&lt;br /&gt;from Sales.Individual&lt;br /&gt;&amp;nbsp;--TotalPurchaseYTD&lt;br /&gt;&amp;nbsp;with xmlnamespaces(default&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;'http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey')&lt;br /&gt;select SUM(demographics.value('sum(/IndividualSurvey/TotalPurchaseYTD)', 'decimal(10,2)')) AS NumberofISurveys&lt;br /&gt;from Sales.Individual&lt;br /&gt;&lt;br /&gt;--avg TotalChildren&lt;br /&gt;&amp;nbsp;with xmlnamespaces(default&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;'http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey')&lt;br /&gt;select &amp;nbsp;(demographics.value('sum(/IndividualSurvey/TotalChildren)', 'decimal(10,2)')) AS NumberofISurveys&lt;br /&gt;from Sales.Individual&lt;br /&gt;&lt;br /&gt;---NODES&lt;br /&gt;&lt;br /&gt;declare @orders xml;&lt;br /&gt;set @orders = N'&lt;br /&gt;&lt;orders&gt;&lt;/orders&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;order &amp;nbsp;qty="2" product="Bike1"&gt;a &lt;/order&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;order &amp;nbsp;qty="3" product="Bike2"&gt;b &lt;/order&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;order &amp;nbsp;qty="4" product="Bike3"&gt; c&lt;/order&gt;&lt;br /&gt;';&lt;br /&gt;&amp;nbsp;SELECT nref.value('Order[1]', 'nvarchar(50)') rowOrder &amp;nbsp;--get first element [1]&lt;br /&gt;&amp;nbsp;,nref.value('Product[1]', 'nvarchar(50)') rowOrderProduct&lt;br /&gt;FROM &amp;nbsp; @orders.nodes('//Orders') AS R(nref)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;DECLARE @T varchar(max)&lt;br /&gt;SET @T =&lt;br /&gt;'&lt;root&gt;&lt;/root&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;field fieldrowid="1000"&gt;&lt;/field&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;items&gt;&lt;/items&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;item name="CODE"&gt;&lt;/item&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;item name="DATE"&gt;&lt;/item&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;attributes&gt;&lt;/attributes&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;attribute id="1"&gt;&lt;/attribute&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;field fieldrowid="2000"&gt;&lt;/field&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;items&gt;&lt;/items&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;item name="CODE"&gt;&lt;/item&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;item name="DATE"&gt;&lt;/item&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;attributes&gt;&lt;/attributes&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;attribute id="2"&gt;&lt;/attribute&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;'&lt;br /&gt;&lt;br /&gt;DECLARE @X xml&lt;br /&gt;&lt;br /&gt;SET @X = CAST(@T as xml)&lt;br /&gt;SELECT&lt;br /&gt;&amp;nbsp;&amp;nbsp; YY.t.value('(@FieldRowId)[1]', 'int') as FieldID,&lt;br /&gt;&amp;nbsp;&amp;nbsp; YY.t.value('(Items/Item/@Name)[1]', 'varchar(max)') as "Name",&lt;br /&gt;&amp;nbsp;&amp;nbsp; YY.t.value('(Attributes/Attribute/@ID)[1]', 'int') as AttributeID&lt;br /&gt;FROM @X.nodes('/root/Field') as YY(t)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-4671738426169013132?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/4671738426169013132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/08/notes-about-xml-processing-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/4671738426169013132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/4671738426169013132'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/08/notes-about-xml-processing-in-sql.html' title='notes about xml processing in sql server'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-1461783463293405485</id><published>2010-07-17T18:56:00.000-07:00</published><updated>2010-07-17T18:56:56.986-07:00</updated><title type='text'>How to call stored procs from User Defined Functions (udf) in SQL Server</title><content type='html'>If you want to use stored procs from your functions , it is not possible with simple "exec sp_myproc".&lt;br /&gt;&lt;br /&gt;You can use openquery to call your server as linked server and execute stored procs.&lt;br /&gt;You need to run some commands before running openquery.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;Step-1: enable openquery&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;---open query to have access to stored procs within functions&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;--add your server as linked server&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;sp_addlinkedserver @server = 'LOCALSERVER', @srvproduct = '', @provider = 'SQLOLEDB', @datasrc = @@servername&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;Step-2: enable data access&lt;div&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;EXEC sp_serveroption 'OMER-PC', 'DATA ACCESS', TRUE&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; ---Check access&lt;/div&gt;&lt;div&gt;Step-3: Select * from openquery(LOCALSERVER, 'Exec sp_who')&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This query should return some results. Openquery does not work for every stored proc. You need to look into the details.&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Some simple examples:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1)--inline table function calling stored proc&lt;br /&gt;-----------------------------------------------------------&lt;br /&gt;create FUNCTION Test.udfCallProcInline()&lt;br /&gt;&amp;nbsp;returns &amp;nbsp;table&lt;br /&gt;AS&lt;br /&gt;return &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;select * from openquery(LOCALSERVER, 'Exec sys.sp_tables')&lt;br /&gt;&amp;nbsp;GO&lt;br /&gt;&lt;div&gt;--------------------------------------------------------------&lt;/div&gt;&lt;div&gt;You can call your function as normal udfs:&lt;/div&gt;&lt;div&gt;&lt;div&gt;select * from Test.udfCallProcInline()&lt;/div&gt;&lt;div&gt;It is also&amp;nbsp;possible&amp;nbsp;to make joins and select columns from the results. You don't need to know column data types here.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2-)-multi statement function&lt;/div&gt;&lt;div&gt;&lt;div&gt;--you may need to check column data types here&lt;/div&gt;&lt;div&gt;CREATE FUNCTION Test.udfCallAProc2()&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;returns @mytable table&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; (table_qualifier varchar(50),&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;table_owner varchar(50),&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;table_name varchar(50),&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;table_type varchar(50),&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;remarks &amp;nbsp;varchar(255)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;AS&lt;/div&gt;&lt;div&gt;begin&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;insert @mytable&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;select * from openquery(LOCALSERVER, 'Exec sys.sp_tables')&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp;return&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;end&lt;/div&gt;&lt;div&gt;GO&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;select * from Test.udfCallAProc2()&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;----More examples....later...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-1461783463293405485?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/1461783463293405485/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/07/how-to-call-stored-procs-from-user.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/1461783463293405485'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/1461783463293405485'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/07/how-to-call-stored-procs-from-user.html' title='How to call stored procs from User Defined Functions (udf) in SQL Server'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-6485993600074458848</id><published>2010-06-22T18:00:00.000-07:00</published><updated>2010-06-22T18:07:13.670-07:00</updated><title type='text'>Recommended Software Related Tools</title><content type='html'>&lt;div style="color: #240f02; font-size: 12px; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;Source Control and Bug track:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://www.mantisbt.org/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;http://www.mantisbt.org/&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;&amp;nbsp;, Mantis: Open source bug tracking system for multiple projects. It is free!&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;http://&lt;/span&gt;&lt;/span&gt;&lt;a href="http://www.blogger.com/goog_1218363240"&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;git&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;a href="http://git-scm.com/"&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;-scm.com/ &lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;,&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;Fast version control system. It is free and open source.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://subversion.tigris.org/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;http://subversion.tigris.org/&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;&amp;nbsp;, Subversion: Open source code repository and code control. Multiplatform and feature rich.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;b&gt;Windows Administration:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://www.sysinternals.com/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;http://www.SysInternals.com&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="line-height: 16px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;Microsoft acquired Sysinternals in July, 2006. Whether you’re an IT Pro or a developer, you’ll find Sysinternals utilities to help you manage, troubleshoot and diagnose your Windows systems and applications.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://www.logparser.com/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;http://www.logparser.com/&lt;/a&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;b&gt;Web Development:&lt;/b&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="https://addons.mozilla.org/en-US/firefox/addon/1843" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;FireBug&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;, Excellent addon tool for Fire Fox. You should have this.&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://notepad-plus.sourceforge.net/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;NotePad++&amp;nbsp;&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;Very good&amp;nbsp;geneal purpose text editor.&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://www.wampserver.com/en/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;WAMP&lt;/a&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;Apache, MySQL, PHP on Windows. Single install with utilities if you don't want to mess with configs.&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;&lt;a href="http://jquery.com/"&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;jQuery:&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;Excellent javascript library. Check also &lt;/span&gt;&lt;a href="http://www.trirand.com/blog/"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;JQGRID&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt; and &lt;/span&gt;&lt;a href="http://jqueryui.com/"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;JQuery UI&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt; tools.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;b&gt;Desktop Apps:&lt;/b&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://www.7-zip.org/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;7-Zip&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;, file compresison, multiple formats, open source.&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://filezilla.sourceforge.net/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;FileZilla&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;, my FTP &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://www.free-codecs.com/download/K_Lite_Codec_Pack.htm" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;KLite Codec Pack&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;, codecs.&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;a href="http://portableapps.com/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;Portable Apps&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;, you can carry your favorite portable programs in a USB drive.&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: Verdana, Arial, Helvetica, Lucida, sans-serif; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;Use any USB flash drive, portable hard drive, iPod/MP3 player, etc&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;b&gt;Interesting:&lt;/b&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&amp;nbsp;&lt;a href="http://eyeos.org/" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #c97e00; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_top"&gt;http://eyeos.org/&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;&amp;nbsp;open source web OS. There are others out there, but this is Open Source and apears stable.&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;b&gt;&amp;nbsp;Content Management Systems:&lt;/b&gt;&lt;/div&gt;&lt;div style="color: #240f02; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 15px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 7px; padding-left: 0px; padding-right: 0px; padding-top: 7px;"&gt;&lt;b&gt;&lt;a href="http://www.blogger.com/goog_1218363276"&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;CMS Made Simple&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;a href="http://www.cmsmadesimple.org/"&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;span class="Apple-style-span" style="color: #cccccc;"&gt;It is really simple and powerful. You can add code snippets inside layouts and it is evaluated in run time. It has admin menu to change layouts and styles. you can also edit them. You can install different Modules or develop your own module. It has good level of supporting documentation.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-6485993600074458848?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/6485993600074458848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/06/recommended-software-related-tools.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/6485993600074458848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/6485993600074458848'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/06/recommended-software-related-tools.html' title='Recommended Software Related Tools'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-5244393866832657980</id><published>2010-06-10T06:43:00.000-07:00</published><updated>2010-06-10T06:43:51.021-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='FREE'/><title type='text'>FREE</title><content type='html'>FREE ADVICE!&lt;br /&gt;&lt;br /&gt;What happens if you delete default database for a user in sql server?&lt;br /&gt;--You will get an error msg as :&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 17px; font-weight: bold;"&gt;Cannot open user default database&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 17px; font-weight: bold;"&gt;--Easy solution: &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 17px; font-weight: bold;"&gt;1- Click options in login window&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 17px; font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 17px; font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-size: 11px; font-weight: normal;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_mHCrhAzxcpY/TBDpleMTcuI/AAAAAAAAAqE/nj5R0C54krM/s1600/server_change1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_mHCrhAzxcpY/TBDpleMTcuI/AAAAAAAAAqE/nj5R0C54krM/s320/server_change1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;Login Screen in SQL Server Management Studio&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;h1 class="title" style="-webkit-box-sizing: border-box; font-size: 17px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;2-Set database to master or model&lt;/h1&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_mHCrhAzxcpY/TBDp463QuRI/AAAAAAAAAqM/QmIZZXAO2ww/s1600/server_change2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_mHCrhAzxcpY/TBDp463QuRI/AAAAAAAAAqM/QmIZZXAO2ww/s320/server_change2.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;Change database for connection&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;b&gt;3-This will fix your login problem. Next step is to find your default database and change that. It is normally located in security&amp;gt; logins&amp;gt; your loginname&lt;/b&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_mHCrhAzxcpY/TBDrhAitZeI/AAAAAAAAAqc/kLLukDr4pGs/s1600/server_change3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_mHCrhAzxcpY/TBDrhAitZeI/AAAAAAAAAqc/kLLukDr4pGs/s320/server_change3.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;Find your Login settings in security tab&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;4-Change your default database if it is not changed.&amp;nbsp;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_mHCrhAzxcpY/TBDrkLtsAeI/AAAAAAAAAqk/44jDUl_zdp0/s1600/server_change4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_mHCrhAzxcpY/TBDrkLtsAeI/AAAAAAAAAqk/44jDUl_zdp0/s320/server_change4.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;Now, you can fix the problem with your default database. Here is the cause of the problem from Mic:&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="line-height: 16px;"&gt;The user default database is unavailable at the time of connection. It is possible that the database:&lt;ul style="-webkit-box-sizing: border-box; position: relative;"&gt;&lt;li style="-webkit-box-sizing: border-box; position: relative;"&gt;Is in suspect mode.&lt;/li&gt;&lt;li style="-webkit-box-sizing: border-box; position: relative;"&gt;No longer exists.&lt;/li&gt;&lt;li style="-webkit-box-sizing: border-box; position: relative;"&gt;Is in single user mode and the only available connection is already being used by someone else or by something else.&lt;/li&gt;&lt;li style="-webkit-box-sizing: border-box; position: relative;"&gt;Has been detached.&lt;/li&gt;&lt;li style="-webkit-box-sizing: border-box; position: relative;"&gt;Has been set to the RESTRICTED_USER state.&lt;/li&gt;&lt;li style="-webkit-box-sizing: border-box; position: relative;"&gt;Is offline.&lt;/li&gt;&lt;li style="-webkit-box-sizing: border-box; position: relative;"&gt;Is set to emergency status.&lt;/li&gt;&lt;li style="-webkit-box-sizing: border-box; position: relative;"&gt;Does not have the login account mapped to a user or the user has been denied access.&lt;/li&gt;&lt;li style="-webkit-box-sizing: border-box; position: relative;"&gt;Is part of a database mirror.&lt;/li&gt;&lt;/ul&gt;Additionally, the login account may be a member of multiple groups and the default database for one of those groups is unavailable at the time of connection.--&amp;gt;&lt;/span&gt;&lt;a href="http://support.microsoft.com/kb/307864"&gt;http://support.microsoft.com/kb/307864&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-5244393866832657980?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/5244393866832657980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/06/free.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/5244393866832657980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/5244393866832657980'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/06/free.html' title='FREE'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_mHCrhAzxcpY/TBDpleMTcuI/AAAAAAAAAqE/nj5R0C54krM/s72-c/server_change1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-4680837980612799629</id><published>2010-05-15T22:50:00.000-07:00</published><updated>2010-05-15T22:50:08.191-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php eclipse zend'/><title type='text'>Eclipse Php Zend Debugger</title><content type='html'>How to Debug PhP Code in ECLIPSE?&lt;br /&gt;If you want to see variable values with mouse over and change them to see the effect in your program without echo statements, you need debugging. You can follow the steps below to set up a php editor with debugging. You can email me for questions.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Install apache server&lt;/li&gt;&lt;li&gt;Install Php from www.php.net&lt;/li&gt;&lt;ol&gt;&lt;li&gt;Select all necessary items such as mysql, openssl, dba&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;Download ZEND plugins for eclipse&lt;/li&gt;&lt;ol&gt;&lt;li&gt;Copy zenddebugger.dll to PHP directory&lt;/li&gt;&lt;li&gt;Add these to your php.ini file&lt;/li&gt;&lt;/ol&gt;&lt;/ol&gt;&lt;div style="text-align: left;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;zend_extension_ts=.\ZendDebugger.dll&lt;/div&gt;&lt;div style="text-align: left;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;zend_debugger.allow_hosts= 127.0.0.1&lt;/div&gt;&lt;div style="text-align: left;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;zend_debugger.expose_remotely=always&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;You may want to run phpinfo() script to see your actual php.ini file. You may have one copy at C:Windows directory.&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;4. Download Eclipse php editor with debugger. It will show you xdebug and zend for debugging.&lt;/div&gt;&lt;div style="text-align: left;"&gt;5. Setup your work directory&lt;/div&gt;&lt;div style="text-align: left;"&gt;6. Configure your debug options: it may launch at http://localhost. This is fine for the default settings.&lt;/div&gt;&lt;div style="text-align: left;"&gt;7. Restart apache server after changing php.ini file&lt;/div&gt;&lt;div style="text-align: left;"&gt;8. When you run in debug mode, Eclipse will ask you to load in perspective show detail debug screen&lt;/div&gt;&lt;div style="text-align: left;"&gt;9. If you get error about php.ini directives, you should check you php.ini file. You can add phpinfo(); command line to list all properties of PHP. It will show you the address of php.ini file.&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;Summary: If you see zend debugger properties in your PHP property list, you have the debugging. Disable Xdebug if you have that. Zend and Xdebug may not work properly at the same time.&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;I am happy to have debugging in php. I guess no more "echo this echo that"&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;Best Regards,&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ol&gt;&lt;ol&gt;&lt;/ol&gt;&lt;/ol&gt;&lt;ol&gt;&lt;ol&gt;&lt;/ol&gt;&lt;/ol&gt;&lt;ol&gt;&lt;ol&gt;&lt;/ol&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-4680837980612799629?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/4680837980612799629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/05/eclipse-php-zend-debugger.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/4680837980612799629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/4680837980612799629'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/05/eclipse-php-zend-debugger.html' title='Eclipse Php Zend Debugger'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-9052698392727130090</id><published>2010-05-13T21:47:00.000-07:00</published><updated>2010-05-13T21:47:51.200-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hosting'/><title type='text'>ASP Hosting</title><content type='html'>I am looking for asp hosting. Most of the hosting providers are offering similar services.&lt;br /&gt;Check the list:&lt;br /&gt;&lt;a href="http://www.hosting-review.com/hosting-directory/top-10-lists/Top-10-ASP-Hosting-Companies.shtml"&gt;http://www.hosting-review.com/hosting-directory/top-10-lists/Top-10-ASP-Hosting-Companies.shtml&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;"&gt;&amp;nbsp;&lt;span style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;IX Web Hosting looks good with the low price tag.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;"&gt;&lt;span style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;1-How much does it cost to use asp hosting with sql server 2008?&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;--It looks like with 36 month plan, they charge around 10$ /month at IX web hosting.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;2-Reliability ?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;3-Support ?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;4-Speed&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;5-Bandwidth limits&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;"&gt;&lt;span style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;I will look into more details about this...Let me know your favorite Hosting provider for Windows!!!&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;"&gt;&lt;span style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;"&gt;&lt;span style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Another info:&amp;nbsp;http://www.dotnetpanel.com/ is open source now. You can download that and use it for hosting management.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;"&gt;&lt;span style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-9052698392727130090?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/9052698392727130090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/05/asp-hosting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/9052698392727130090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/9052698392727130090'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/05/asp-hosting.html' title='ASP Hosting'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-602056012848521180</id><published>2010-04-27T06:24:00.000-07:00</published><updated>2010-05-13T21:15:06.061-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='T-SQL Transaction LOCKS'/><title type='text'>Transaction and Locks in MS SQL 2008</title><content type='html'>Today 's topic is TRANSACTION operations. You can test many concepts with running multiple connections in SQL Server management studio. This article will talk about the type of locks, consistency and update operations. if you have large tables, some data modification statements may take time and block others. You will learn how to read data with different level of consistency and durability. &lt;br /&gt;&lt;br /&gt;Transactions have four basic properties:&amp;nbsp;&lt;b&gt;&amp;nbsp;All-Or-Nothing, Consistency,Isolation, and Durability.&lt;/b&gt;&lt;br /&gt;&lt;b&gt;All-Or-Nothing(Atomicity):&lt;/b&gt;&amp;nbsp;You should keep transactions compact and one unit operation. If the system fails before committing the code, system will rollback the changes automatically. Some errors are not severe enough for automatic rollback such as lock expiration time-out, key violation. You can add your Try/Catch blocks to decide for a rollback. You can also check @@TRANCOUNT to find out if there is any open transactions.&lt;br /&gt;print 'Current Trans Ccount: ' + cast(    @@TRANCOUNT as varchar(50))&lt;br /&gt;&lt;b&gt;Consistency:&lt;/b&gt;&amp;nbsp;At the end of the transaction, you may have your new and valid data accepted or rollback to original state.You can control the consistency of the data with different lock levels at resources. &lt;add more=""&gt;&lt;br /&gt;&lt;b&gt; Isolation:&lt;/b&gt;&amp;nbsp;&amp;nbsp;Before the data is committed or rollback to the original state , It is kept in isolation and not accessible to other transactions. You can control the lock level for each resource in the database. Type of Lock status defines your consistency for different levels of acces. You will see in the examples.&lt;br /&gt;&lt;b&gt; Durability:&lt;/b&gt; The transaction is considered durable after commit instruction is written to the transaction log on disk. When system restarts it can check transaction logs, to apply committed changes if it is not recorded in data portion.&amp;nbsp;&lt;/add&gt;&lt;br /&gt;&lt;add more=""&gt;&lt;br /&gt;&lt;/add&gt;&lt;br /&gt;&lt;add more=""&gt;Each individual INSERT, DELETE, UPDATE statement is an individual transaction and committed automatically without rollback. You can also use those statements within begin transaction and commit transaction to check for rollback state.&lt;/add&gt;&lt;br /&gt;&lt;add more=""&gt;&lt;br /&gt;&lt;/add&gt;&lt;br /&gt;&lt;add more=""&gt;--TIP: ROLLBACK statement may return the data to its previous state, but it may not reset your identity column seed values.&lt;/add&gt;&lt;br /&gt;&lt;add more=""&gt;&lt;br /&gt;&lt;b&gt; LOCKS&lt;/b&gt;:  Lock settings help you to modify the resources with the level of customized consistency from your  transaction. When you try to modify data, your transaction asks for an exclusive lock on the data resource, if it is granted, it will keep the lock until the end of transaction. Only one exclusive lock is available at that resource and other request will wait for the end of the transaction. When you read the data, server asks for a shared lock and it does not place shared lock over exclusive. We will go into details of these locks, but it will help you if you can see list of locks in your database.&lt;br /&gt;&lt;br /&gt;&lt;/add&gt;&lt;br /&gt;&lt;add more=""&gt;You can lock Row, Page, Object, Database and other type of resources&lt;add link=""&gt;.  Different than your main lock type, SQL server add intent locks at higher level than your locked resource. If your transaction is using exclusive lock at the row level, intent locks will be placed at the page level and the table level.&lt;br /&gt;You can query the current locks and waiting request at your server with the following query:&lt;br /&gt;--QUERY for all sessions&lt;br /&gt;SELECT &lt;br /&gt;request_session_id                AS spid,&lt;br /&gt;resource_type                     AS restype,&lt;br /&gt;resource_database_id              AS dbid,&lt;br /&gt;DB_NAME(resource_database_id)     as DBNAME,&lt;br /&gt;resource_description              AS res,&lt;br /&gt;resource_associated_entity_id     AS resid,&lt;br /&gt;CASE &lt;br /&gt;when resource_type = 'OBJECT' then  OBJECT_NAME( resource_associated_entity_id)  &lt;br /&gt;ELSE 'N/A'&lt;br /&gt;END  as ObjectName,&lt;br /&gt;request_mode                      AS mode,&lt;br /&gt;request_status                    AS status&lt;br /&gt;FROM sys.dm_tran_locks&lt;br /&gt;order by spid, restype;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You don't see any exclusive request right now in the figure above. We have Shared locks granted.  If you run the following query at your Adventureworks Db, you will see the list of locks at different levels. &amp;lt; I assume you have that from MS SQL Samples.&amp;gt;&lt;br /&gt;&lt;br /&gt;BEGIN TRAN;&lt;br /&gt;&lt;br /&gt;UPDATE Production.Product&lt;br /&gt;SET ListPrice = 0.15&lt;br /&gt;where productid =4&lt;br /&gt;&lt;br /&gt;--Commit tran;   --Commit this later. We want to see the current request.&lt;br /&gt;&lt;br /&gt;print 'Current Trans Ccount: ' + cast(    @@TRANCOUNT as varchar(50))&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Figure: Our uncommitted transaction is showing X (Exclusive) lock at the row key.&lt;br /&gt;&lt;br /&gt;Since we have foreign key relations to other tables, server will automatically add shared intent (IS) locks to those  tables. We have the Exclusive intent (IX) lock at the Product table and Page resource.  Our row key has an exclusive lock (X) from SPID-56. This SPID is at the bottom of the query page. Each query page will have an unique SPID.  If you run another query from a new query window, we can exercise wait blocks.&lt;br /&gt;&lt;br /&gt;Run this query at another query page and check waiting processes again with sys.dm_tran_locks:&lt;br /&gt;SELECT * from production.product&lt;br /&gt;where ProductID = 4;&lt;br /&gt;&lt;br /&gt;Here is our waiting list:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;My new query page has SPID of 59 and previous page has SPID of 56. You may different numbers in your system. Process-59 is waiting for the resource to lock for Shared mode. Since process-56 is locked this row for an EXCLUSIVE lock, Shared lock will not be applied over that. &lt;br /&gt;In simple terms, you don't get shared lock when another transaction is holding an exclusive lock. You can have multiple shared locks as you might guess. If you really want to read this row before uncommitted, you can set isolation level of READ UNCOMMITTED.&lt;br /&gt;Open another query window and type this:&lt;br /&gt;SET transaction isolation level read uncommitted;&lt;br /&gt;SELECT * from production.product&lt;br /&gt;where ProductID = 4&lt;br /&gt;This query will read it immediately without waiting for the commitment of the transaction. If you rollback the transaction or do some other modifications to this data at the same transaction, other query result will be INCONSISTENT.&lt;br /&gt;NOLOCK is same as specifiying "READ UNCOMMITTED". If you run this query, you will get uncommited data without waiting for the resource:&lt;br /&gt;SELECT * from production.product with (nolock )&lt;br /&gt;where ProductID = 4 &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can specify READ COMMITTED, which is default for select statements, to read with shared lock. It will show you the data after update statements. &lt;br /&gt;&lt;br /&gt;Duration of this lock is important. Reader use shared lock for "READ COMMITTED" state until it is finished with this reosurce. It is not going to keep this lock until the end of the transaction. You may get inconsistent results if another transaction modify your data in between your reads, becuase you are not keeping shared lock untill the end of your transaction.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want to read data and make sure that others do not change the values in between your reads, you can specify "REPEATABLE READ" isolation level.&lt;br /&gt;&lt;br /&gt;SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;&lt;br /&gt;BEGIN TRAN;&lt;br /&gt;select * from production.product  &lt;br /&gt;where ProductID = 4 &lt;br /&gt;&lt;br /&gt;Other users may insert rows even if you have "REPEATABLE READ" lock. This may change your reader output and result in inconsistent data. You can use SERIALIZABLE LOCK to prevent that.&lt;br /&gt;&lt;br /&gt;SERIALIZABLE LOCK:  You can lock row insert operations with serializable lock. this will prevent insert operations on your resource while you were reading it with this lock option. &lt;br /&gt;&lt;br /&gt;Snapshot Isolation Levels&lt;br /&gt;&lt;br /&gt;If you enable any of the snapshot based isolation levels, DELETE and UPDATE statements will copy the row before the change at resource to the "tempdb". SELECT statements will have better performance , but Modifications will be slower. Readers using snapshot level isolations will not use shared locks, so they don't need to wait for the resource. You need to turn on this option if you want to use it.&lt;br /&gt;&lt;br /&gt;With the Snapshot isolation, reader will check the last committed version of the resource, so it is doing row versioning. &lt;br /&gt;&lt;br /&gt;When you use Snapshot level access, you request last committed version of the resource. &lt;br /&gt;SET TRANSACTION ISOLATION LEVEL SNAPSOT;&lt;br /&gt;BEGIN TRAN;&lt;br /&gt;select * from production.product  &lt;br /&gt;where ProductID = 4 &lt;br /&gt;&lt;br /&gt;This query will checkout the latest committed row data and if you start another transaction after this statement to change same rowdata and committed, you will still read from your version.&lt;br /&gt;&lt;br /&gt;Now to test this, first open a new query window and run this query. It is reading from last committed row.  &lt;br /&gt;&lt;br /&gt;--QUERY1:&lt;br /&gt;Alter database adventureworks set allow_snapshot_isolation on;&lt;br /&gt;SET TRANSACTION ISOLATION LEVEL snapshot&lt;br /&gt;BEGIN TRAN;&lt;br /&gt;select * from Production.Product&lt;br /&gt;where ProductID = 2;&lt;br /&gt;--Commit TRAN  --commit later&lt;br /&gt;You will see latest committed product-2.  &lt;br /&gt;&lt;br /&gt;Now, Open an another window and run QUERY2. It will run that immediately without waiting. If you go back to other page and run only select statement in QUERY1, you will not see the updated price. Because we are still using previous version of the row.  If you commit the transaction at QUERY1 and run it again, you will see the changes. &lt;br /&gt;&lt;br /&gt;--QUERY2:&lt;br /&gt;UPDATE Production.Product&lt;br /&gt;SET ListPrice = 0.35&lt;br /&gt;where productid =2&lt;br /&gt;&lt;br /&gt;If you want to read latest data within your transaction, you can use "READ COMMITTED SNAPSHOT" isolation level. Readers will not use shared locks, and do not need to wait within this transaction. They will get latest version of the data. You need to set READ_COMMITTED_SNAPSHOT flag to ON to use this.&lt;br /&gt;&lt;br /&gt;Lock TYPE Uncommitted&lt;br /&gt;Data Consistency ISSUE within current TRANS RESTRICT Updates within current TRANS RESTRICT INSERT within current TRANS DETECT UPDATE CONFLICTS within current TRANS ROW VERSIONs Holds &lt;br /&gt;Lock to end of TRANS&lt;br /&gt;READ UNCOMMITTED Yes Yes No No No No Lowest level&lt;br /&gt;READ COMMITTED No Yes No No No No NO&lt;br /&gt;REPEATABLE READ No No Yes No No,but&lt;br /&gt;(DEADLOCK) No YES&lt;br /&gt;SERIAlizable No No Yes Yes No,but&lt;br /&gt;(DEADLOCK) No Yes&lt;br /&gt;READ COMMITTED SNAPSHOT No Yes No No No Yes --&lt;br /&gt;SNAPSHOT No No YES YES YES(Fails transaction) YES --&lt;br /&gt;Table: Properties of different lock types within a transaction&lt;br /&gt;&lt;br /&gt;DEADLOCK: Transaction queries may block each other if ask for same resource with high level access. SQL server detects the deadlock and rollback the transaction which has lower amount work.&lt;br /&gt;&lt;br /&gt;If you want to see blocking and waiting resources with their sql text, you can run next query::You can add more information from sys.dm_exec_connections, sys.dm_exec_sessions, sys.dm_exec_requests, and system function to get sql-text( sys.dm_exec_sql_text).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;WITH CTE as   --THIS IS a table expression&lt;br /&gt;(&lt;br /&gt;SELECT &lt;br /&gt;request_session_id                AS spid,&lt;br /&gt;resource_type                     AS restype,&lt;br /&gt;resource_database_id              AS dbid,&lt;br /&gt;DB_NAME(resource_database_id)     as DBNAME,&lt;br /&gt;resource_description              AS res,&lt;br /&gt;resource_associated_entity_id     AS resid,&lt;br /&gt;CASE &lt;br /&gt;when resource_type = 'OBJECT' then  OBJECT_NAME( resource_associated_entity_id)  &lt;br /&gt;ELSE 'N/A'&lt;br /&gt;END  as ObjectName,&lt;br /&gt;request_mode                      AS mode,&lt;br /&gt;request_status                    AS status&lt;br /&gt;FROM sys.dm_tran_locks&lt;br /&gt;)&lt;br /&gt;select sc.session_id as WAITINGSESSIONID,&lt;br /&gt;BLOCKS.spid as FirstBLOCKINGID,&lt;br /&gt;mn.DBNAME,mn.mode as WAITingMODE,&lt;br /&gt;(select text from sys.dm_exec_sql_text( sc.most_recent_sql_handle) ) as SQLWAITING,&lt;br /&gt;(select text from sys.dm_exec_sql_text( BLOCKS.most_recent_sql_handle) ) as SQLBLOCKING&lt;br /&gt;from CTE mn join sys.dm_exec_connections sc on mn.spid = sc.session_id&lt;br /&gt;cross apply  &lt;br /&gt;(&lt;br /&gt;select  top 1  * from CTE sub join sys.dm_exec_connections sc on sub.spid = sc.session_id&lt;br /&gt;where sub.res = mn.res and sub.status = 'GRANT' &lt;br /&gt;) as BLOCKS &lt;br /&gt;where mn.status = 'WAIT' ;&lt;br /&gt;&lt;br /&gt;If you are not comfortable with cross apply and CTE type tables, you can check articles about that from my blog.&lt;br /&gt;&lt;br /&gt;SUMMARY:&lt;br /&gt;1. Default request is shared lock for SELECT statements and they wait for the resource if it is locked as "Exclusive" for modifications.&lt;br /&gt;2. You can read uncommitted data:: select &amp;lt;...&amp;gt; from &lt;table..&gt;with(NOLOCK) ::-&amp;gt; will give you uncommitted dirty data. 3. Server adds intent locks at higher level of the resource to make quick checks for resource state. 4. READ MORE from MSDN website if you are curious about LOCKS and Transactions 5. Waiting and blocking sessions may change, so you need to be careful if you want to kill a process. (You can kill the process like: KILL 52 (52 is SPID). If you kill the process before it finishes the transaction, system may rollback the changes. You need to check details on that. It might not do a good job if it is a long transaction. 6. Keep Transactions as simple as possible to reduce deadlocks and wait.&lt;/table..&gt;&lt;/add&gt;&lt;/add&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-602056012848521180?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/602056012848521180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/04/transaction-and-locks-in-ms-sql-2008.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/602056012848521180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/602056012848521180'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/04/transaction-and-locks-in-ms-sql-2008.html' title='Transaction and Locks in MS SQL 2008'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-7801414444790429629</id><published>2010-04-25T14:47:00.000-07:00</published><updated>2010-04-25T14:47:22.254-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='datetime sql datediff'/><title type='text'>How to find start and end of the month as Datetime in SQL</title><content type='html'>While waiting at McDonalds, I decide to make a small post.&lt;br /&gt;&lt;br /&gt;Some examples to get the start and the end of the month as datetime field.&lt;br /&gt;&lt;br /&gt;Declare @mysearch datetime&lt;br /&gt;Declare @StartDate datetime&lt;br /&gt;Declare @EndDate datetime&lt;br /&gt;set @mysearch = '20100401 00:00:01';&lt;br /&gt;--First day of the month as Datetime field&lt;br /&gt;set @StartDate =  dateadd(ms,0,DATEADD(mm, DATEDIFF(m,0,getdate()  ), 0));&lt;br /&gt;--Last day of the month as Datetime field&lt;br /&gt;&amp;nbsp;&amp;nbsp; set @EndDate =   dateadd(ms,0,DATEADD(mm, DATEDIFF(m,0,getdate()  )+1, 0)) ;&lt;br /&gt;&amp;nbsp; if (@mysearch &amp;gt;= @StartDate and @mysearch &amp;lt; @EndDate)&lt;br /&gt;&amp;nbsp;&amp;nbsp; print 'Between this datetime'   else    print 'Not Between this datetime'&lt;br /&gt;--In this example,we are using DATEDIFF, DATEADD, and GetDATE() functions.&lt;br /&gt;&lt;br /&gt;DATEDIFF ( datepart , startdate , enddate ): You can set the datepart from nanosecond to year. It basically gives you the difference between startdate and enddate.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;::To find difference in years:&lt;/b&gt;&lt;br /&gt;SELECT DATEDIFF(year, '2003-01-01', '2006-01-01'); --&amp;gt; will give you 3 as a difference. You can specify startdate and enddate in different formats. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;::TO find difference in hrs:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;SELECT DATEDIFF(HOUR, '2010-04-22 22:59:59.9999999'&lt;br /&gt;, '2010-04-23 00:00:00.0000000');--&amp;gt;this will give you 2 hrs.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Now if you run this::&lt;/b&gt;&lt;br /&gt;SELECT DATEDIFF(HOUR, '2010-04-22 23:59:59.9999999'&lt;br /&gt;, '2010-04-23 00:00:00.0000000');--&amp;gt;&lt;b&gt;You will get 1hr difference. If you run for minutes, you will get 1 minute. As you might guess, it will also give 1 for difference in days. &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;::Referenced Datetime&lt;br /&gt;In our first example we used 0 as our reference datetime field. You will still get the same result even if you set something else. We are simply taking difference and adding over the referenced datetime. &lt;br /&gt;&lt;br /&gt;declare @REFERENCE datetime&lt;br /&gt;set @REFERENCE = '20100401'&lt;br /&gt;&lt;br /&gt;select dateadd(ms,0,DATEADD(mm, DATEDIFF(m,@REFERENCE,getdate()  )+1, @REFERENCE))&lt;br /&gt;&lt;br /&gt;If you specify this @REFERENCE as '20100401 10:12:12', you will get time field in your result. Output: 2010-05-01 10:12:12.000&lt;br /&gt;&lt;br /&gt;Using same technique we can find many other datetime fields::&lt;br /&gt;&lt;br /&gt;::LAST DAY OF THE PREVIOUS YEAR as Datetime&lt;br /&gt;select  dateadd(ms, -3, DATEADD(yy, DATEDIFF( year,0,getdate()  ), 0)) &lt;br /&gt;::FIRST DAY OF this week &lt;br /&gt;select   DATEADD(week, DATEDIFF(week,0,getdate()  ),0);&lt;br /&gt;::LAST DAY of this week&lt;br /&gt;select   dateadd(day,-1,DATEADD(week, DATEDIFF(week,0,getdate()  )+1,0));&lt;br /&gt;::Last day of this week within ms for datetime comparison&lt;br /&gt;select   dateadd(ms,-3,DATEADD(week, DATEDIFF(week,0,getdate()  )+1,0));&lt;br /&gt;&lt;br /&gt;::I guess you figured out how to do the other possible cases.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-7801414444790429629?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/7801414444790429629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/04/how-to-find-start-and-end-of-month-as.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/7801414444790429629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/7801414444790429629'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/04/how-to-find-start-and-end-of-month-as.html' title='How to find start and end of the month as Datetime in SQL'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-5981929370058738801</id><published>2010-04-25T14:45:00.000-07:00</published><updated>2010-04-25T14:45:29.406-07:00</updated><title type='text'>::SQL Helpers</title><content type='html'>&lt;b&gt;I will add some of the useful sql functions:&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;::COLUMN NAMES in a Table&lt;/b&gt;&lt;br /&gt;select name  from sys.columns&lt;br /&gt;where object_id = OBJECT_ID(N'Sales.Orders');&lt;br /&gt;&lt;br /&gt;&lt;b&gt;::Information about schema views&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;lists the user tables in the current database along with their schema names&lt;br /&gt;select table_schema, table_name, IST.TABLE_TYPE, IST.TABLE_CATALOG&lt;br /&gt;from INFORMATION_SCHEMA.TABLES IST&lt;br /&gt;--where TABLE_TYPE = N'Base table'&lt;br /&gt;&lt;br /&gt;&lt;b&gt;::List of tables in the database&lt;/b&gt;&lt;br /&gt;exec sys.sp_tables;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;::Waiting and Blocking Processes&lt;/b&gt;&lt;br /&gt;&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"&gt;&lt;/meta&gt;&lt;meta content="Word.Document" name="ProgId"&gt;&lt;/meta&gt;&lt;meta content="Microsoft Word 12" name="Generator"&gt;&lt;/meta&gt;&lt;meta content="Microsoft Word 12" name="Originator"&gt;&lt;/meta&gt;&lt;link href="file:///C:%5CUsers%5Comer%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml" rel="File-List"&gt;&lt;/link&gt;&lt;link href="file:///C:%5CUsers%5Comer%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx" rel="themeData"&gt;&lt;/link&gt;&lt;link href="file:///C:%5CUsers%5Comer%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml" rel="colorSchemeMapping"&gt;&lt;/link&gt;    &lt;m:smallfrac m:val="off"&gt;    &lt;m:dispdef&gt;    &lt;m:lmargin m:val="0"&gt;    &lt;m:rmargin m:val="0"&gt;    &lt;m:defjc m:val="centerGroup"&gt;    &lt;m:wrapindent m:val="1440"&gt;    &lt;m:intlim m:val="subSup"&gt;    &lt;m:narylim m:val="undOvr"&gt;   &lt;/m:narylim&gt;&lt;/m:intlim&gt; &lt;/m:wrapindent&gt;&lt;style&gt;&lt;!-- /* Font Definitions */ @font-face	{font-family:Calibri;	panose-1:2 15 5 2 2 2 4 3 2 4;	mso-font-charset:0;	mso-generic-font-family:swiss;	mso-font-pitch:variable;	mso-font-signature:-520092929 1073786111 9 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal	{mso-style-unhide:no;	mso-style-qformat:yes;	mso-style-parent:"";	margin-top:0in;	margin-right:0in;	margin-bottom:10.0pt;	margin-left:0in;	line-height:115%;	mso-pagination:widow-orphan;	font-size:11.0pt;	font-family:"Calibri","sans-serif";	mso-ascii-font-family:Calibri;	mso-ascii-theme-font:minor-latin;	mso-fareast-font-family:"Times New Roman";	mso-fareast-theme-font:minor-fareast;	mso-hansi-font-family:Calibri;	mso-hansi-theme-font:minor-latin;	mso-bidi-font-family:"Times New Roman";	mso-bidi-theme-font:minor-bidi;}.MsoChpDefault	{mso-style-type:export-only;	mso-default-props:yes;	mso-ascii-font-family:Calibri;	mso-ascii-theme-font:minor-latin;	mso-fareast-font-family:"Times New Roman";	mso-fareast-theme-font:minor-fareast;	mso-hansi-font-family:Calibri;	mso-hansi-theme-font:minor-latin;	mso-bidi-font-family:"Times New Roman";	mso-bidi-theme-font:minor-bidi;}.MsoPapDefault	{mso-style-type:export-only;	margin-bottom:10.0pt;	line-height:115%;}@page Section1	{size:8.5in 11.0in;	margin:1.0in 1.0in 1.0in 1.0in;	mso-header-margin:.5in;	mso-footer-margin:.5in;	mso-paper-source:0;}div.Section1	{page:Section1;}--&gt;&lt;/style&gt;&lt;span style="font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11pt; line-height: 115%;"&gt;Run this query at another query page and check waiting processes again with &lt;/span&gt;&lt;span style="color: green; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; line-height: 115%;"&gt;sys&lt;/span&gt;&lt;span style="color: grey; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; line-height: 115%;"&gt;.&lt;/span&gt;&lt;span style="color: green; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; line-height: 115%;"&gt;dm_tran_locks&lt;/span&gt;&lt;/m:defjc&gt;&lt;/m:rmargin&gt;&lt;/m:lmargin&gt;&lt;/m:dispdef&gt;&lt;/m:smallfrac&gt;&lt;br /&gt;&lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"&gt;&lt;/meta&gt;&lt;meta content="Word.Document" name="ProgId"&gt;&lt;/meta&gt;&lt;meta content="Microsoft Word 12" name="Generator"&gt;&lt;/meta&gt;&lt;meta content="Microsoft Word 12" name="Originator"&gt;&lt;/meta&gt;&lt;link href="file:///C:%5CUsers%5Comer%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml" rel="File-List"&gt;&lt;/link&gt;&lt;link href="file:///C:%5CUsers%5Comer%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_editdata.mso" rel="Edit-Time-Data"&gt;&lt;/link&gt;&lt;link href="file:///C:%5CUsers%5Comer%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx" rel="themeData"&gt;&lt;/link&gt;&lt;link href="file:///C:%5CUsers%5Comer%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml" rel="colorSchemeMapping"&gt;&lt;/link&gt;    &lt;m:smallfrac m:val="off"&gt;    &lt;m:dispdef&gt;    &lt;m:lmargin m:val="0"&gt;    &lt;m:rmargin m:val="0"&gt;    &lt;m:defjc m:val="centerGroup"&gt;    &lt;m:wrapindent m:val="1440"&gt;    &lt;m:intlim m:val="subSup"&gt;    &lt;m:narylim m:val="undOvr"&gt;   &lt;/m:narylim&gt;&lt;/m:intlim&gt; &lt;/m:wrapindent&gt;&lt;style&gt;&lt;!-- /* Font Definitions */ @font-face	{font-family:Calibri;	panose-1:2 15 5 2 2 2 4 3 2 4;	mso-font-charset:0;	mso-generic-font-family:swiss;	mso-font-pitch:variable;	mso-font-signature:-520092929 1073786111 9 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal	{mso-style-unhide:no;	mso-style-qformat:yes;	mso-style-parent:"";	margin-top:0in;	margin-right:0in;	margin-bottom:10.0pt;	margin-left:0in;	line-height:115%;	mso-pagination:widow-orphan;	font-size:11.0pt;	font-family:"Calibri","sans-serif";	mso-ascii-font-family:Calibri;	mso-ascii-theme-font:minor-latin;	mso-fareast-font-family:"Times New Roman";	mso-fareast-theme-font:minor-fareast;	mso-hansi-font-family:Calibri;	mso-hansi-theme-font:minor-latin;	mso-bidi-font-family:"Times New Roman";	mso-bidi-theme-font:minor-bidi;}.MsoChpDefault	{mso-style-type:export-only;	mso-default-props:yes;	mso-ascii-font-family:Calibri;	mso-ascii-theme-font:minor-latin;	mso-fareast-font-family:"Times New Roman";	mso-fareast-theme-font:minor-fareast;	mso-hansi-font-family:Calibri;	mso-hansi-theme-font:minor-latin;	mso-bidi-font-family:"Times New Roman";	mso-bidi-theme-font:minor-bidi;}.MsoPapDefault	{mso-style-type:export-only;	margin-bottom:10.0pt;	line-height:115%;}@page Section1	{size:8.5in 11.0in;	margin:1.0in 1.0in 1.0in 1.0in;	mso-header-margin:.5in;	mso-footer-margin:.5in;	mso-paper-source:0;}div.Section1	{page:Section1;}--&gt;&lt;/style&gt;  &lt;/m:defjc&gt;&lt;/m:rmargin&gt;&lt;/m:lmargin&gt;&lt;/m:dispdef&gt;&lt;/m:smallfrac&gt;&lt;br /&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;SELECT&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; request_session_id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; spid&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; resource_type&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; restype&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; resource_database_id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: blue;"&gt;dbid&lt;/span&gt;&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="position: relative; z-index: 251664384;"&gt;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; &lt;span style="color: magenta;"&gt;DB_NAME&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt;resource_database_id&lt;span style="color: grey;"&gt;)&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;as&lt;/span&gt; DBNAME&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; resource_description&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; res&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; resource_associated_entity_id &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; resid&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; &lt;span style="color: blue;"&gt;CASE&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;when&lt;/span&gt; resource_type &lt;span style="color: grey;"&gt;=&lt;/span&gt; &lt;span style="color: red;"&gt;'OBJECT'&lt;/span&gt; &lt;span style="color: blue;"&gt;then&lt;/span&gt;&amp;nbsp; &lt;span style="color: magenta;"&gt;OBJECT_NAME&lt;/span&gt;&lt;span style="color: grey;"&gt;(&lt;/span&gt; resource_associated_entity_id&lt;span style="color: grey;"&gt;)&lt;/span&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;ELSE&lt;/span&gt; &lt;span style="color: red;"&gt;'N/A'&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; &lt;span style="color: blue;"&gt;END&lt;/span&gt;&amp;nbsp; &lt;span style="color: blue;"&gt;as&lt;/span&gt; ObjectName&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; request_mode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; mode&lt;span style="color: grey;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;&amp;nbsp; request_status&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;AS&lt;/span&gt; &lt;span style="color: blue;"&gt;status&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;FROM&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt; &lt;span style="color: green;"&gt;sys&lt;/span&gt;&lt;span style="color: grey;"&gt;.&lt;/span&gt;&lt;span style="color: green;"&gt;dm_tran_locks&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"&gt;&lt;span style="color: blue; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;order&lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt; &lt;span style="color: blue;"&gt;by&lt;/span&gt; spid&lt;span style="color: grey;"&gt;,&lt;/span&gt; restype&lt;span style="color: grey;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: green; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; line-height: 115%;"&gt;&amp;nbsp;&lt;/span&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-5981929370058738801?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/5981929370058738801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/04/sql-helpers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/5981929370058738801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/5981929370058738801'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/04/sql-helpers.html' title='::SQL Helpers'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-3138590792531027747</id><published>2010-04-15T17:46:00.000-07:00</published><updated>2010-04-15T17:46:54.119-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL DELETE MERGE ORDER TOP  SQLSERVER  2008 database'/><title type='text'>SQL Merging DATA</title><content type='html'>&lt;strong&gt;:::SQL MERGE&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SQL server 2008 has a new feature to merge tables with actions for different conditions.&lt;br /&gt;&lt;br /&gt;Here is an example for&amp;nbsp;your reference:&lt;br /&gt;&lt;br /&gt;MERGE INTO dbo.Target as TT&lt;br /&gt;using dbo.Source as SS&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on TT.keyid = SS.keyid&lt;br /&gt;WHEN MATCHED THEN&lt;br /&gt;&amp;nbsp;&amp;nbsp; UPDATE SET&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TT.col1 = SS.col1,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TT.col2&amp;nbsp; =&amp;nbsp;SS.col2,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;TT.col3 = SS.col3,&lt;br /&gt;&amp;nbsp;WHEN NOT MATCHED THEN&lt;br /&gt;&amp;nbsp; INSERT (col1,col2, col3,colX,colY )&lt;br /&gt;&amp;nbsp; values (SS.col1,SS.col2,SS.col3,SS.colX,SS.colY);&lt;br /&gt;&lt;br /&gt;--you need to use semicolon to finish the statement!&lt;br /&gt;&lt;br /&gt;You can use merge statement to insert new table data to the existing table. You can also do the same operation with multiple insert, update , delete statements.&lt;br /&gt;&lt;br /&gt;If you want to specify multiple conditions for matched case, you can do that.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;MERGE INTO dbo.Target as TT&lt;br /&gt;using dbo.Source as SS&lt;br /&gt;&amp;nbsp;on TT.keyid = SS.keyid&lt;br /&gt;&amp;nbsp;WHEN MATCHED &lt;strong&gt;AND (&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp; TT.col1 &amp;lt;&amp;gt; SS.col1&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;nbsp; OR TT.col2 &amp;lt;&amp;gt; SS.col2 )&lt;/strong&gt;&amp;nbsp; THEN&lt;br /&gt;UPDATE SET&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TT.col1 = SS.col1,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TT.col2 = SS.col2&lt;br /&gt;&amp;nbsp; WHEN NOT MATCHED THEN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INSERT (col1,col2, col3,colX,colY )&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values (SS.col1,SS.col2,SS.col3,SS.colX,SS.colY);&lt;br /&gt;&lt;br /&gt;You can update the related record, if it justifies your condition. You can monitor transactions with this statement. If there is a change in the record, you can add that to audit records.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;:::HOW TO DELETE with TOP Option and USE ordering&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Well, you might want to delete top 10 product reviews based on Ordering of&amp;nbsp;low ratings. Ordering will not work directly. A logical ORDER BY for the top option in a modification statement is not allowed. When you say :&lt;br /&gt;&lt;br /&gt;::&amp;gt;Delete top 10 from dbo.myreviews; &lt;br /&gt;&lt;br /&gt;It will delete arbitrary records. if you want to order them, you can use table expressions.&lt;br /&gt;&lt;br /&gt;WITH C as&lt;br /&gt;( &lt;br /&gt;&amp;nbsp;&amp;nbsp; select top( 10 ) * &lt;br /&gt;&amp;nbsp;&amp;nbsp; from dbo.myreviews&lt;br /&gt;&amp;nbsp;&amp;nbsp; order by rating asc&lt;br /&gt;)&lt;br /&gt;DELETE FROM C;&lt;br /&gt;&lt;br /&gt;Now, you got rid of the bad ratings for your product.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-3138590792531027747?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/3138590792531027747/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/04/sql-merging-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/3138590792531027747'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/3138590792531027747'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/04/sql-merging-data.html' title='SQL Merging DATA'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-1872749935292958864</id><published>2010-04-14T18:17:00.000-07:00</published><updated>2010-04-14T18:17:33.090-07:00</updated><title type='text'>SQL : Deleting Data</title><content type='html'>I will add more sql related topics. How do we delete data?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;::SQL Delete Statement&lt;/strong&gt;&lt;br /&gt;The standard statement has two parts "from" and&amp;nbsp; "where".&lt;br /&gt;&lt;u&gt;Example:&lt;/u&gt;&lt;br /&gt;DELETE from dbo.mytabletodelete&lt;br /&gt;WHERE recordno &amp;lt; 15;&lt;br /&gt;&lt;br /&gt;This statement basically deletes records based on where clause.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;strong&gt;::TRUNCATE&lt;/strong&gt;&lt;br /&gt;This statement deletes all rows from a table. It performs better than delete statement. Truncate resets identity value back to original seed. One good protection to delete all rows from a table is to set foreign keys on this table. Truncate statement does not work if the target table is referenced by a foreign key constraint.&lt;br /&gt;&lt;u&gt;Example:&lt;/u&gt;&lt;br /&gt;Truncate Table dbo.mytableallrows;&lt;br /&gt;&lt;br /&gt;USE AdventureWorks;&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;--Copy some table to dummy table for testing&lt;br /&gt;Select * into dbo.truncatetest&lt;br /&gt;from HumanResources.JobCandidate;&lt;br /&gt;&lt;br /&gt;SELECT COUNT(*) AS BeforeTruncateCount &lt;br /&gt;FROM dbo.truncatetest;&lt;br /&gt;&lt;br /&gt;TRUNCATE TABLE dbo.truncatetest;&lt;br /&gt;&lt;br /&gt;SELECT COUNT(*) AS AfterTruncateCount &lt;br /&gt;FROM dbo.truncatetest;&lt;br /&gt;&lt;br /&gt;GO&lt;strong&gt;::DELETE With A &amp;nbsp;Join Operation&lt;/strong&gt; &lt;br /&gt;You may want to delete filtered records&amp;nbsp; from the join operation. You can join multiple tables and check columns from those tables. &lt;br /&gt;&amp;nbsp; &lt;br /&gt;DELETE FROM T1&lt;br /&gt;from dbo.atable as T1&lt;br /&gt;&amp;nbsp;join dbo.btable as T2 &lt;br /&gt;&amp;nbsp;on T1.rowid = T2.rowid&lt;br /&gt;where T1.afield = "something" and T2.anotherfield = "another"&lt;br /&gt;&lt;br /&gt;Wow, we delete records from table T1 based on two conditions. You can write complex queries to filter what to delete.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;::Delete with Top option&lt;/strong&gt;&lt;br /&gt;You can specify how many records to delete. If you want to take top 10 of some ordered list, you can do that.&lt;br /&gt;&amp;nbsp;USE AdventureWorks;&lt;br /&gt;&lt;br /&gt;DELETE TOP (2) PERCENT &lt;br /&gt;FROM Production.ProductInventory;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;::SQL UPDATE Statement&lt;/strong&gt;&lt;br /&gt;It allows you to update a subset from a table. If we start with the simple example:&lt;br /&gt;&lt;br /&gt;UPDATE dbo.Products&lt;br /&gt;&amp;nbsp; Set&amp;nbsp;price =&amp;nbsp;price * 1.1&lt;br /&gt;WHERE Color = "blue"&lt;br /&gt;&lt;br /&gt;Update happens in one call, so you can easily assign one column to anotherr column. &lt;br /&gt;&lt;br /&gt;Update Table1&lt;br /&gt;&amp;nbsp;Set col1 = col1 + 5, col2 = col1 + 3;&lt;br /&gt;&lt;br /&gt;if Col1 is 10 and Col2 is 15 before the assignment, their values will be 15 and 13 after the assignment.&lt;br /&gt;&lt;br /&gt;You can Update rows based on a join. This is similar to DELETE operation.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;::UPdate based on a Join&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;UPDATE PR &lt;br /&gt;&lt;br /&gt;Set price = price * 1.1 &lt;br /&gt;from dbo.Products as PR&lt;br /&gt;&amp;nbsp; join dbo.Orders as O&lt;br /&gt;&amp;nbsp; on PR.productid = O.productid&lt;br /&gt;&lt;br /&gt;WHERE PR.Color = "blue" and O.orderstatus = "incomplete"&lt;br /&gt;&amp;nbsp; &lt;br /&gt;::Here, we use Orders table to find records with specific orderstatus for an update operation.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;::OUTPUT Clause in Update&lt;/strong&gt;&lt;br /&gt;--if you are curious to see the column values before the update and after the update, you can use OUTPUT clause to return them&lt;br /&gt;&lt;br /&gt;UPDATE dbo.OrderDetails&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set priority = priority +1&lt;br /&gt;OUTPUT&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;inserted.productid, deleted.priority as oldp,&lt;br /&gt;&amp;nbsp; &amp;nbsp; inserted.priority as newp&lt;br /&gt;where&amp;nbsp; productid &amp;gt; 91;&lt;br /&gt;&lt;br /&gt;------The end---------Next---&amp;gt; MERGe operations---&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-1872749935292958864?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/1872749935292958864/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/04/sql-deleting-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/1872749935292958864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/1872749935292958864'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/04/sql-deleting-data.html' title='SQL : Deleting Data'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-6257152635539405848</id><published>2010-03-30T20:22:00.000-07:00</published><updated>2010-03-30T20:22:13.174-07:00</updated><title type='text'>SQL Commands Lookup : INSERT</title><content type='html'>I decide to keep some notes here. It may help you as well.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;==========Insert Statements=========================&lt;/strong&gt;&lt;br /&gt;--You can insert records into table without specifying the column names.&lt;br /&gt;INSERT INTO table_name&lt;br /&gt;&lt;br /&gt;VALUES (value1, value2, value3,...)&lt;br /&gt;&lt;br /&gt;It may be better to specify columns for some cases.&lt;br /&gt;INSERT INTO table_name (column1, column2, column3,...)&lt;br /&gt;&lt;br /&gt;VALUES (value1, value2, value3,...)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--Multiple records can be inserted as well. SQL Server 2008 has "values" clause.&lt;br /&gt;&lt;br /&gt;insert into dbo.myorders (orderid, orderdate, empid, custid)&lt;br /&gt;values&lt;br /&gt;(102, '20090212', 4, 'B'),&lt;br /&gt;(103, '20090212', 1, 'A'),&lt;br /&gt;(104, '20090212', 5, 'C'),&lt;br /&gt;(105, '20090212', 6, 'D');&lt;br /&gt;&lt;br /&gt;You can create this table to test it.&lt;br /&gt;&lt;br /&gt;create table dbo.myorders&lt;br /&gt;&lt;br /&gt;( &lt;br /&gt;&amp;nbsp; orderid int not null&lt;br /&gt;&amp;nbsp; constraint PK_myorders primary key,&lt;br /&gt;&amp;nbsp; orderdate date not null&lt;br /&gt;&amp;nbsp; constraint dft_orderdate default(current_timestamp),&lt;br /&gt;&amp;nbsp;empid int not null,&lt;br /&gt;&amp;nbsp;custid varchar(10) not null&lt;br /&gt;&amp;nbsp;)&lt;br /&gt;&lt;br /&gt;==&lt;strong&gt;Insert Select &lt;/strong&gt;statement inserts the rows returned by SELECT query into a target table. &lt;br /&gt;&lt;br /&gt;insert into dbo.myorders (orderid, orderdate, empid, custid)&lt;br /&gt;SELECT orderid, orderdate, empid, custid&lt;br /&gt;from SomeOrderTable&lt;br /&gt;where shipcountry = 'USA';&lt;br /&gt;&lt;br /&gt;This query will insert all selected records into our table.&lt;br /&gt;&lt;br /&gt;==&lt;strong&gt;Insert Exec &lt;/strong&gt;statement is similar to "insert select", but you can insert result set returned from sql procedure. We will create a simple stored proc to show this.&lt;br /&gt;&lt;br /&gt;create PROC proc_getorders&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; @custid as int &lt;br /&gt;as &lt;br /&gt;&lt;br /&gt;select orderid, orderdate, empid, custid&lt;br /&gt;from Sales.Orders&lt;br /&gt;where custid = @custid;&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;This proc will return a table for a given customer id. We can insert&amp;nbsp;returned result from stored proc easily with "Insert ...exec" statement.&lt;br /&gt;INSERT INTO dbo.myorders(orderid, orderdate, empid, custid)&lt;br /&gt;&amp;nbsp; EXEC dbo.proc_getorders 5;&lt;br /&gt;&lt;br /&gt;===Insert with "SELECT INTO"&lt;br /&gt;You can use to create copy of the tables. This statement copies column names, null cases, identity, and types from source table. However, it does not copy constraints, indexes, and triggers. &lt;br /&gt;&lt;br /&gt;SELECT orderid, orderdate, empid, custid&lt;br /&gt;INTO dbo.myorder_copy&lt;br /&gt;from dbo.myorder&lt;br /&gt;&lt;br /&gt;You are not going to have primary key and default value constraint at your myorder_copy table.&lt;br /&gt;Bulk insert dbo.myorders from 'C:\SomeDirectory\myorderdata.txt'&lt;br /&gt;&lt;br /&gt;with&lt;br /&gt;( &lt;br /&gt;&amp;nbsp;datafiletype = 'char',&lt;br /&gt;&amp;nbsp;fieldterminator = ',',&lt;br /&gt;&amp;nbsp;rowterminator = '\n'&lt;br /&gt;);&lt;br /&gt;You can create a txt file similar to this: &lt;br /&gt;2003,20090102,1,3&lt;br /&gt;2004,20090102,1,6&lt;br /&gt;&lt;br /&gt;====Insert and IDENTITY &amp;nbsp;property====&lt;br /&gt;I showed examples without identity column. If you have columns with autogenerated type, you can skip that field when inserting data.&lt;br /&gt;You can make another table with auto generated column. IDENTITY(2,3) will set starting number to&amp;nbsp;2 and increment to 3. You need to create constraints with different names, so add something to their name. &lt;br /&gt;&lt;br /&gt;create table dbo.myorderAutoID&lt;br /&gt;&lt;br /&gt;( &lt;br /&gt;orderid int not null identity(1,1),&lt;br /&gt;constraint PK2_myorders primary key,&lt;br /&gt;&lt;br /&gt;&amp;nbsp;orderdate date not null&lt;br /&gt;constraint dft2_orderdate default(current_timestamp),&lt;br /&gt;empid int not null,&lt;br /&gt;custid varchar(10) not null&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;Now, you can add records. Table will have auto generated order id. &lt;br /&gt;&lt;br /&gt;insert into dbo.myorderAutoID ( orderdate, empid, custid)&lt;br /&gt;&lt;br /&gt;values&lt;br /&gt;( '20090212', 4, 'B'),&lt;br /&gt;( &amp;nbsp;'20090212', 4, 'B'),&lt;br /&gt;&lt;br /&gt;( &amp;nbsp;'20090212', 4, 'B');&lt;br /&gt;&lt;br /&gt;&lt;a href="mailto:==@@identity"&gt;==@@identity&lt;/a&gt; and SCOPE_IDENTITY() will return last generated identity value in current session. If you call those after your insert operation, it will give last identity value.&lt;br /&gt;Run "Select @@identity; " to see the last generated identity value. If you want to get last identity value produced, you can use IDENT_CURRENT function. It is related to the table.&lt;br /&gt;&lt;br /&gt;Select IDENT_CURRENT('dbo.myorderAutoID') will return 3, because you entered only 3 records to the table. &lt;br /&gt;&lt;br /&gt;If these records are not inserted for some reason, table will skip the identity value. If your record is rejected and not inserted, table will not use that id. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;insert into dbo.myorderAutoID ( orderdate, empid, custid)&lt;br /&gt;values&lt;br /&gt;(null , 4, 'B');&lt;br /&gt;&lt;br /&gt;This query will skip the identity 4 and next inserted row will have identity value of 5. &lt;br /&gt;&lt;br /&gt;===End of Insert===&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-6257152635539405848?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/6257152635539405848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/03/sql-commands-lookup-insert.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/6257152635539405848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/6257152635539405848'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/03/sql-commands-lookup-insert.html' title='SQL Commands Lookup : INSERT'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-8565984409878381306</id><published>2010-03-30T19:03:00.000-07:00</published><updated>2010-03-30T19:03:45.505-07:00</updated><title type='text'>SQL Coalesce</title><content type='html'>If you want to convert null fields into something else inside your select command, you can do that with "Coalesce".&lt;br /&gt;&lt;br /&gt;select&lt;br /&gt;&lt;br /&gt;custid, coalesce( region, ' ')&amp;nbsp; as region&lt;br /&gt;from Sales.Customers&lt;br /&gt;order by region;&lt;br /&gt;&lt;br /&gt;This SQL query will show null regions as space.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-8565984409878381306?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/8565984409878381306/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/03/sql-coalesce.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/8565984409878381306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/8565984409878381306'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/03/sql-coalesce.html' title='SQL Coalesce'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-645031315867409681.post-3312710764114718654</id><published>2010-03-15T19:11:00.000-07:00</published><updated>2010-03-30T19:05:00.580-07:00</updated><title type='text'>My first post!</title><content type='html'>&lt;strong&gt;&lt;u&gt;CROSS APPLY&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;Examples are based on AdventureWorks DB. You can find that from &lt;a href="http://msdn.microsoft.com/en-us/library/ms124659.aspx"&gt;MSDN&lt;/a&gt; and install that with your express version of sql server 2008. I will post links about how to setup that.&lt;br /&gt;&lt;br /&gt;I like the "Cross Apply" command in MS SQL. It gives you access to left side of the join and you can perform operations for each row from left side.&lt;br /&gt;&lt;br /&gt;Normally cross join operator performs cartesion product if you don't specify where statement in your query.&lt;br /&gt;&lt;br /&gt;USE AdventureWorks;&lt;br /&gt;GO&lt;br /&gt;Select p.SalesPerson, st.Name as Territory&lt;br /&gt;from Sales.SalesPerson p&lt;br /&gt;cross join Sales.SalesTerritory st&lt;br /&gt;&lt;br /&gt;This query will produce total of nxm rows. You don't have access to table p inside table st.&lt;br /&gt;&lt;br /&gt;You can do much better with Cross Apply.&lt;br /&gt;&lt;br /&gt;1- &lt;strong&gt;This will calculate avg qty in orders and total number of orders for each product.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;select pt.ProductID, pt.Name, pt.StandardCost, A.num_orders, A.avg_order&lt;br /&gt;from Production.Product pt&lt;br /&gt;cross apply(&lt;br /&gt;select count(distinct sd.SalesOrderID) as num_orders, avg(sd.OrderQty) as avg_order&lt;br /&gt;from Sales.SalesOrderDetail as sd&lt;br /&gt;where sd.ProductID = pt.ProductID&lt;br /&gt;&lt;br /&gt;) as A&lt;br /&gt;order by num_orders desc;&lt;br /&gt;&lt;br /&gt;2-&lt;strong&gt;Latest 3 orders per customer&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Select c.CustomerID, A.SalesOrderID, A.orderdate&lt;br /&gt;&lt;br /&gt;from Sales.Customer as c&lt;br /&gt;cross apply(&lt;br /&gt;&amp;nbsp;&amp;nbsp; select top(3) O.SalesOrderID, O.SalesPersonID, O.OrderDate,O.DueDate&lt;br /&gt;&amp;nbsp;&amp;nbsp; from sales.SalesOrderHeader as O &lt;br /&gt;&amp;nbsp;&amp;nbsp; where O.CustomerID = c.CustomerID&lt;br /&gt;&amp;nbsp;&amp;nbsp; order by orderdate desc, SalesOrderID desc&lt;br /&gt;) as A;&lt;br /&gt;&lt;br /&gt;3-Other examples......&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/645031315867409681-3312710764114718654?l=omerc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://omerc.blogspot.com/feeds/3312710764114718654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://omerc.blogspot.com/2010/03/hello-world.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/3312710764114718654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/645031315867409681/posts/default/3312710764114718654'/><link rel='alternate' type='text/html' href='http://omerc.blogspot.com/2010/03/hello-world.html' title='My first post!'/><author><name>Omer Cansizoglu</name><uri>http://www.blogger.com/profile/14338607611916060699</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
