1
<%@ CodeTemplate Language="C#" TargetLanguage="T-SQL" Description="Create a procedure which have insert function base on a table." %>
2
<%@ Assembly Name="SchemaExplorer" %>
3
<%@ Import Namespace="SchemaExplorer" %>
4
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="DataTable" Description="Table that the stored procedures should be based on." %>
5
<%@ Property Name="Author" Type="String" Category="Context" Description="The author for this procedure."%>
6
<%@ Property Name="Description" Type="String" Category="Context" Description="The description for this procedure."%>
7
<script runat="template">
8
public string GetSqlParameterStatement(ColumnSchema column)
9
{
10
string param = "@" + column.Name + " " + column.NativeType;
11
switch (column.DataType)
12
{
13
case DbType.Decimal:
14
{
15
param += "(" + column.Precision + ", " + column.Scale + ")";
16
break;
17
}
18
default:
19
{
20
if (column.Size > 0)
21
{
22
param += "(" + column.Size + ")";
23
}
24
break;
25
}
26
}
27
return param;
28
}
29
</script>
30
CREATE PROCEDURE dbo.<%=SourceTable.Name %>Insert
31
/*
32
==================================================
33
Author:<%= Author %>
34
CreatedTime:<%= System.DateTime.Now.ToShortDateString() %>
35
Description:<%= Description %>
36
==================================================
37
*/
38
<% for (int i = 0; i < SourceTable.Columns.Count; i++) { %>
39
<%= GetSqlParameterStatement(SourceTable.Columns[i]) %><% if (i < SourceTable.Columns.Count - 1) { %>,<% } %> <% if (SourceTable.Columns[i].Description != "") { %>--<%= SourceTable.Columns[i].Description %><% } %>
40
<% } %>
41
AS
42
Insert Into [<%= SourceTable.Name %>]
43
(
44
<% for (int i = 0; i < SourceTable.Columns.Count; i++) { %>
45
[<%= SourceTable.Columns[i].Name %>]<% if (i < SourceTable.Columns.Count - 1) { %>,<% } %> <% if (SourceTable.Columns[i].Description != "") { %>--<%= SourceTable.Columns[i].Description %><% } %>
46
<% } %>
47
)
48
Values
49
(
50
<% for (int i = 0; i < SourceTable.Columns.Count; i++) { %>
51
@<%= SourceTable.Columns[i].Name %><% if (i < SourceTable.Columns.Count - 1) { %>,<% } %>
52
<% } %>
53
)
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