<%@ 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 %>Insert31
/*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
AS42
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
Values49
(50
<% for (int i = 0; i < SourceTable.Columns.Count; i++) { %>51
@<%= SourceTable.Columns[i].Name %><% if (i < SourceTable.Columns.Count - 1) { %>,<% } %>52
<% } %>53
)










