pitan.net - // Todo: Add some magic here!?

Funny

Found this http://xkcd.com/327/ Damn now I know what to name my children. >< 


Actions: E-mail | del.icio.us | Permalink | RSS

SQL Merge Part 1

 T-SQL Merge and Strongly Typed DataSets

Merge is a great new function in sql 2008 (other databases have had it for a while I know)

I'm currently working in a project where I mixed it with a strongly typed dataset. It saved me allot of time when it came to updating/inserting tabels

First off the MERGE command

The tabel Identification handel som user information about there Identification. (Face2Face)

 First off i create a row with the incoming information.

[code=sql] 

USING (
  SELECT 
  @Label as Label ,
  @Info as Info,
  @Creator as Creator,
  @CreateDate as CreateDate,
  @PartyID as PartyID
  ) AS src

Then the magic. 

ON (Identification.PartyID = [src].PartyID) 

This will check with the destionation table if there is a row there that matches

if so Update else Insert 

 The whol thing... 

MERGE Table 
USING (
  SELECT 
  @Label as Label ,
  @Info as Info,
  @Creator as Creator,
  @CreateDate as CreateDate,
  @PartyID as PartyID
  ) AS src
 ON (Identification.PartyID = [src].PartyID)
 WHEN MATCHED THEN

UPDATE SET 
   
 Label = @Label ,
 Info = @Info ,
 CreateDate =@CreateDate ,
 PartyID = @PartyID 
   
 
 WHEN NOT MATCHED THEN
 INSERT ([Label]
  ,[Info]
  ,[Creator]
  ,[CreateDate]
  ,[PartyID])
  VALUES
  (@Label
  ,@Info
  ,@Creator
  ,@CreateDate
  ,@PartyID)

;


 

This is run inte a stored procedure called IndentificationSave

 

So there you have a Save command

Next part Strongly typed DataSet

 

 


Actions: E-mail | del.icio.us | Permalink | RSS