This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- 快速計算所有Data Table的筆數 | |
-- 原理:使用其table實體檔的partitions預存的筆數再加總即可取得。 | |
-- ref-> [Row_Count_All_Tables.sql] https://gist.github.com/kr153/0148a3f50080012101a3 | |
-- | |
SELECT sc.NAME AS SchemaName, ta.NAME AS TableName, SUM(pa.rows) AS RowCnt | |
FROM sys.tables ta | |
INNER JOIN sys.partitions pa ON pa.OBJECT_ID = ta.OBJECT_ID | |
INNER JOIN sys.schemas sc ON ta.schema_id = sc.schema_id | |
WHERE ta.is_ms_shipped = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' | |
' 此例使用VB6之 RecordSet 新增資料到資料庫 | |
' | |
Private Sub OKButton_Click() | |
On Error GoTo ErrorHandler | |
'# resource | |
Dim rs As New ADODB.Recordset | |
Dim fields(8) As Variant ' 注意陣列大小需與下面的應用呼應 | |
Dim values(8) As Variant ' 注意陣列大小需與下面的應用呼應 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Rem | |
Rem 此類別程式碼需搭配相應的Word範本檔 | |
Rem | |
'# Parameters - word document template filename | |
Public WordDotFilename As String | |
'# Parameters - bookmark |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ===================================================== | |
-- sp_executesql OUTPUT 範例 | |
-- 說明:動態組織SQL Command,可使用EXEC或sp_executesql。 | |
-- 使用 EXEC,ex: EXEC(@sql); 其中 @sql 放動態組織好的指令,但無法OUTPUT。 | |
-- 使用新指令 sp_executesql 則可以設定 OUTPUT 參數。 | |
-- ===================================================== | |
CREATE PROCEDURE [dbo].[prMyProcedure] | |
@sub_system CHAR(2), | |
@file_no INT, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- new line : | |
-- \r CHAR(13) | |
-- \n CHAR(10) | |
-- | |
DECLARE @MEMO NVARCHAR(MAX); | |
SET @MEMO = N'line 1 line 1 line 1 ' | |
PRINT @MEMO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 當月第一天 | |
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) | |
-- 2015-12-01 00:00:00.000 | |
-- 當月最後一天 | |
SELECT DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE()),-1) | |
-- 2015-12-31 00:00:00.000 | |
-- 相差年數(有小數) | |
SELECT DATEDIFF(MONTH, '2011/6/1', GETDATE()) / 12.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub ParseDate(ByRef tb As TextBox) | |
Rem 自訂函數 | |
On Error GoTo ErrHandle | |
Dim a As Long | |
Dim y, m, d As Integer | |
Dim mod4 As Long | |
y = Year(Now) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ============================================= | |
-- 語法簡化版的資料表值函數範例 | |
-- ============================================= | |
CREATE FUNCTION [dbo].[My_Simmple_Table_Valued_Function] | |
( | |
-- Parameters here | |
@ARN VARCHAR(23) | |
) | |
RETURNS TABLE -- 可省去宣告輸出格式的動作 | |
AS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'# 在VB6中出現"NULL值使用不正確" | |
'# 參考文章http://www.blueshop.com.tw/board/FUM200501271723350KG/BRD200512090832443X3.html | |
'# 法一:使用 IIF 與 IsNull 函數 | |
'# [變數] = IIf(IsNull([變數]), [預設值], [變數]) | |
field_value = IIf(IsNull(rs.Fields(9).Value), "", rs.Fields(9).Value) | |
'# 法二: 串接空字串 | |
'# 變數 = Trim(變數 & "") | |
field_value = rs.Fields(9).Value & "" |