Skip to main content

SQL Server 2008 Merger Statement

The most challenging issue of using SQL jobs to updating procedure is to check unique data with relative table. If you are using SQL Server 2005 or below you would have to write a series of T-SQL statements that check to see if the record exists, and then write an UPDATE or INSERT statement depending on your existence checks.

SQL Server 2008 introduced the Merge statement which is commonly also called as Upsert (Update / Insert). It can be used as Insert if the row does not exists and update, if it exists. It can be used as ETL process while fetching data. This feature is useful for developers. It is not required to give any particular join (inner, left outer etc). Here are a few facts that you must know before starting to use Merge Statement:
  1. Atomic statement combining INSERT, UPDATE and DELETE operations based on conditional logic
  2. Done as a set-based operation; more efficient than multiple separate operations
  3. MERGE is defined by ANSI SQL; you will find it in other database platforms as well
  4. Useful in both OLTP and Data Warehouse environments
    OLTP: merging recent information from external source
    DW: incremental updates of fact, slowly changing dimensions.
A typical merge statement looks like:
merge [dbo].[target] t
using [dbo2].[source] s on t.id = s.id
when not matched then
insert ([column1], [column2], [column3], [column4])
values s.[column1], s.[column2], s.[column3], s.[column4]

Comments

Popular posts from this blog

ASP.NET Core & Angular 2 - Chapter 2 Routing

Route to a component The Angular 2 router is a powerful tool which enables you to do just that. Specifically you can configure it to route to a component when the user enters a specific url for your site. So in this case, we could configure it so that navigating to http://domain/hello routes directly to the hello world component. Open up your app.module.ts file and make the following simple change in routing section. 1 2 3 4 5 6 7 8 9 10 11 imports: [      DefaultModules, //This automatically imports BrowserModule, HttpModule, and JsonpModule too.      RouterModule.forRoot([          { path: '' , redirectTo: 'home' , pathMatch: 'full' },          { path: 'home' , component: HomeComponent },          { path: 'counter' , component: CounterComponent },       ...

ASP.NET Core & Angular 2 - Chapter 3 Display the weather

Display the weather We’ll take a look at how to create a .NET Core Web API controller, retrieve data from it and pass that up to the Angular front end (where it will be rendered as a page on your site). Add Controller Method We’ll initially just add a simple method to the WeatherController to make use of the OpenWeather API to get forecast by City. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 28 29 30 31 32 [HttpGet("[action]/{city}")] public async Task WeatherForecast(string city) { using (var client = new HttpClient()) { try { client.BaseAddress = new Uri("http://api.openweathermap.org"); var response = await client.GetAsync($"/data/2.5/weather?q={city}&appid=[Insert API Key Here ]&units=metric"); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); ...