-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathGetColumnList.ahk
57 lines (43 loc) · 1.21 KB
/
GetColumnList.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
GetColumnList(fnTableName,fnDatabaseName = "xDatabaseNamex")
{
; returns a comma-separated list of the columns for a given table in a database
; MsgBox fnTableName: %fnTableName%`nfnDatabaseName: %fnDatabaseName%
; declare local, global, static variables
Try
{
; set default return value
ColumnList := ""
; validate parameters
If !fnTableName
Throw, Exception("fnTableName was empty",-1,"AlwaysSilent")
; initialise variables
SQL := "
( LTrim
USE xDatabaseNamex
SELECT name
FROM sys.columns
WHERE 1=1
AND [object_id] = OBJECT_ID(N'xTableNamex')
AND is_computed = 0
ORDER BY column_id
)"
; do something
StringReplace, SQL, SQL, xTableNamex, %fnTableName%, All ; insert the table name
StringReplace, SQL, SQL, xDatabaseNamex, %fnDatabaseName%, All ; insert the database name
ColumnList := ExecuteSQL("PROD" ";RowDelim=`,;ColDelim=`t",SQL,0) ; comma separated
}
Catch, ThrownValue
{
CatchHandler(A_ThisFunc,ThrownValue.Message,ThrownValue.What,ThrownValue.Extra,ThrownValue.File,ThrownValue.Line,0,0,0)
}
Finally
{
}
; return
Return ColumnList
}
/* ; testing
params := xxx
ReturnValue := GetColumnList(params)
MsgBox, GetColumnList`n`nReturnValue: %ReturnValue%
*/