發表文章

目前顯示的是 9月, 2018的文章

18 09 26 自我研讀(二)

圖片
== ISNULL(判斷欄位,要替代的值) EX: ISNull(NULL, 'A')   ---A ISNull(12345, 'A')   ---12345 ISNull(NULL, NULL)   ---NULL == COALESCE(函數可為多個參數,回傳第一個不是NULL值的參數,至少要有兩個參數) 以下為例 select ID, NAME, p1,p2,p3, coalesce(p2,p3) from shop_Price --從p2,p3挑出非NULL值(若都為NULL還是會顯示NULL) select ID, NAME, p2,p3, coalesce(p2,p3,0) from shop_Price --從p2,p3,0挑出非NULL值 == EOMONTH(回傳指定日期當月的最後一天) select DATEADD(DAY,1,EOMONTH(GETDATE(),-1)) ; 當月第一天 select EOMONTH(getdate()); 當月最後一天 == ISNUMERIC (判斷是否為有效數值,TRUE為1,FALSE為0) == ISDATE  (判斷是否為 有效日期 ,TRUE為1,FALSE為0) select ISNUMERIC(100),ISNUMERIC(1.5),ISNUMERIC(-10.5),ISNUMERIC('abc'); -- result 1,1,1,0 select ISDATE('2018-09-11'),ISDATE('199033'),ISDATE('abc'); -- result 1,0,0 == TRY_CONVERT(嘗試轉換,若轉換失敗則為NULL) SELECT isitdate,TRY_CONVERT(datetime,isitdate) as converteddate FROM Sales.Somedates; == LIKE 用法 + 萬用字元 1. % : 表任一或多個字元 2. _ : 表任一個字元 3. [ ] :表示括弧內...

TSQL Lab 06 習題

LAB 06 Exercise 1 --------------------------------------------------------------------- -- Task 1 -- -- -- Write a SELECT statement to return columns that contain: --  The current date and time. Use the alias currentdatetime. --  Just the current date. Use the alias currentdate. --  Just the current time. Use the alias currenttime. --  Just the current year. Use the alias currentyear. --  Just the current month number. Use the alias currentmonth. --  Just the current day of month number. Use the alias currentday. --  Just the current week number in the year. Use the alias currentweeknumber. --  The name of the current month based on the currentdatetime column. Use the alias currentmonthname. -- -- Execute the written statement and compare the results that you got with the desired results shown in the file 52 - Lab Exercise 1 - Task 1 Result.txt. Your results will be different because of the current date and time value. -- -- Ca...