2018年1月31日 星期三

C# 日期字串統一格式

//// 定義日期字串
string dateString = "2018/03/10";

//// 字串 -> DateTime
DateTime datetime = Convert.ToDateTime(dateString);

//// DateTime -> 字串(yyyy-MM-dd HH:mm:ss)
String datetimeString = datetime.ToString("yyyy-MM-dd HH:mm:ss");

//// 轉回來的字串才能統一格式
Console.WriteLine(datetimeString);

參考程式 -> C# Online

2018年1月5日 星期五

SQL Case When In Where Condition

SELECT
   column1, 
   column2
FROM
   viewWhatever
WHERE
CASE 
    WHEN @locationType = 'location' AND account_location = @locationID THEN 1
    WHEN @locationType = 'area' AND xxx_location_area = @locationID THEN 1
    WHEN @locationType = 'division' AND xxx_location_division = @locationID THEN 1
    ELSE 0
END = 1
SELECT column1, column2
FROM viewWhatever
WHERE
    (@locationType = 'location' AND account_location = @locationID)
    OR
    (@locationType = 'area' AND xxx_location_area = @locationID)
    OR
    (@locationType = 'division' AND xxx_location_division = @locationID)
By: https://stackoverflow.com/questions/206484/sql-switch-case-in-where-clause

remove last word from SQL query

SET @columnSql = SUBSTRING ( @columnSql , 1 , LEN ( @columnSql ) - 1 )