var lst = dt.AsEnumerable()
.Select(r => r.Table.Columns.Cast<DataColumn>()
.Select(c => new KeyValuePair<string, object>(c.ColumnName, r[c.Ordinal])
).ToDictionary(z=>z.Key,z=>z.Value)
).ToList();
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
return serializer.Serialize(lst);
2015年8月17日 星期一
DataTable to JSON string
2015年8月3日 星期一
Json傳輸 參數字串轉為 javascript function
{
"param1" : "str1",
"num1" : 1,
"someFunction" : "function(){alert(1);}"
}
var obj = JSON.parse(str,turnStrToFunction);
/*************
JSON.parse(str,reviver)
reviver function = > 轉換字串成為javascript function
**************/
function turnStrToFunction (key, value) {
if (value && (typeof value === 'string') && value.indexOf("function(") === 0) {
var jsFunc = new Function('return ' + value)();
return jsFunc;
}
return value;
};
2015年3月28日 星期六
SQL Group By Like , 欄位橫轉直(pivot)
select Year
,Month
,SUM(contactUs)contactUs
,SUM(contactUs)contactUs
,SUM(mamaClubCancel)mamaClubCancel
,SUM(mamaClubSignUp)mamaClubSignUp
,SUM(memberAdd)memberAdd
,SUM(memberLogin)memberLogin
,SUM(mamaClubLogin)mamaClubLogin from (
--pivot start
select YEAR,Month ,contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin
from
(
--groupby start
SELECT Year(cdate) AS 'Year'
, Month(cdate) AS 'Month'
, case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end i_name
, COUNT(DISTINCT fno) total
, COUNT(DISTINCT ino) distint
from SUB_FlowTracking D
GROUP BY Year(cdate), Month(cdate),
--Group By Like
case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end
--groupby end
) d
pivot
( --sum field
SUM(d.total)
--field source field
for i_name in (contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin)
) piv
--pivot end
) T Group by Year,Month
,Month
,SUM(contactUs)contactUs
,SUM(contactUs)contactUs
,SUM(mamaClubCancel)mamaClubCancel
,SUM(mamaClubSignUp)mamaClubSignUp
,SUM(memberAdd)memberAdd
,SUM(memberLogin)memberLogin
,SUM(mamaClubLogin)mamaClubLogin from (
--pivot start
select YEAR,Month ,contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin
from
(
--groupby start
SELECT Year(cdate) AS 'Year'
, Month(cdate) AS 'Month'
, case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end i_name
, COUNT(DISTINCT fno) total
, COUNT(DISTINCT ino) distint
from SUB_FlowTracking D
GROUP BY Year(cdate), Month(cdate),
--Group By Like
case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end
--groupby end
) d
pivot
( --sum field
SUM(d.total)
--field source field
for i_name in (contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin)
) piv
--pivot end
) T Group by Year,Month
訂閱:
文章 (Atom)