Friday, November 13, 2009
How to Update value with JOIN in SQL query?
UPDATE
table1
SET
table1.column1=table2.column1
FROM
table1
INNER JOIN (ANY JOIN)
table2
ON
table1.key=table2.key
Labels:
SQL
Monday, October 12, 2009
How to write a JSON string from .NET c# code for AJAX usage
Assume the variable name of the List is _List
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(_List.GetType());
System.IO.MemoryStream ms = new System.IO.MemoryStream();
serializer.WriteObject(ms, _List);
string json = Encoding.UTF8.GetString(ms.ToArray());
Sunday, September 20, 2009
How to send mail with binary word in mail subject using PHP
Please refer RFC 2047 for detail format.
For simple, if your mail subject contains binary, and I use UTF-8 as a example:
$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
Labels:
php
Sunday, September 13, 2009
Linq Group By 2 columns
from c in db.Customers
group c by new { c.Country, c.City } into g
select new { g.Key.Country, g.Key.City, Count = g.Count() };
Labels:
linq
Friday, September 11, 2009
Left join in LINQ
In SQL:
SELECT * FROM table_A LEFT JOIN table_B WHERE table_A.col=table_B.col
In LINQ:
from a in table_A
join b in table_B on a.col equals b.col into temp
from finalSet in temp.DefaultIfEmpty()
hightlighted is the keywords that using left join in linq
seems using a temp dataset the set the record and fill the missing part in table_B with empty to get the finalSet.
Labels:
linq
Thursday, September 10, 2009
How to remove duplicated 2-dimension array in PHP?
My sample array Data:
$arr[] = array(0,1,2,3);
$arr[] = array(4,5,2,1);
$arr[] = array(0,0,0,0);
$arr[] = array(0,1,2,3);
I expected to return
array(array(0,1,2,3), array(4,5,2,1), array(0,0,0,0));
Solution:
$arr = array_map('unserialize', array_unique(array_map('serialize', $arr)));
$arr = array_map('unserialize', array_unique(array_map('serialize', $arr)));
Labels:
php
Wednesday, September 9, 2009
When to prefer JSON over XML?
Favor XML over JSON when any of these is true:
- You need message validation
- You're using XSLT
- Your messages include a lot of marked-up text
- You need to interoperate with environments that don't support JSON
Favor JSON over XML when all of these are true:
- Messages don't need to be validated, or validating their deserialization is simple
- You're not transforming messages, or transforming their deserialization is simple
- Your messages are mostly data, not marked-up text
- The messaging endpoints have good JSON tools
Labels:
Javascript,
JSON
Subscribe to:
Posts (Atom)