欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【SQLServer编写存储过程小工具(二)】,下面是详细的分享!
SQLServer编写存储过程小工具(二)
CREATEproceduresp_GenInsert
@TableNamevarchar(130),
@ProcedureNamevarchar(130)
as
setnocounton
declare@maxcolint,
@TableIDint
set@TableID=object_id(@TableName)
select@MaxCol=max(colorder)
fromsyscolumns
whereid=@TableID
select'CreateProcedure'+rtrim(@ProcedureName)astype,0ascolorderinto#TempProc
union
selectconvert(char(35),'@'+syscolumns.name)
+rtrim(systypes.name)
+casewhenrtrim(systypes.name)in('binary','char','nchar','nvarchar','varbinary','varchar')then'('+rtrim(convert(char(4),syscolumns.length))+')'
whenrtrim(systypes.name)notin('binary','char','nchar','nvarchar','varbinary','varchar')then''
end
+casewhencolorder<@maxcolthen','
whencolorder=@maxcolthen''
end
astype,
colorder
fromsyscolumns
joinsystypesonsyscolumns.xtype=systypes.xtype
whereid=@TableIDandsystypes.name<>'sysname'
union
select'AS',@maxcol+1ascolorder
union
select'INSERTINTO'+@TableName,@maxcol+2ascolorder
union
select'(',@maxcol+3ascolorder
union
selectsyscolumns.name
+casewhencolorder<@maxcolthen','
whencolorder=@maxcolthen''
end
astype,
colorder+@maxcol+3ascolorder
fromsyscolumns
joinsystypesonsyscolumns.xtype=systypes.xtype
whereid=@TableIDandsystypes.name<>'sysname'
union
select')',(2*@maxcol)+4ascolorder
union
select'VALUES',(2*@maxcol)+5ascolorder
union
select'(',(2*@maxcol)+6ascolorder
union
select
selecttypefrom#tempprocorderbycolorder
droptable#tempproc
以上所分享的是关于SQLServer编写存储过程小工具(二),下面是编辑为你推荐的有价值的用户互动:
相关问题:sql server 2008 怎么编写存储过程
答:第一步:点击数据库下的“可编程性”,选择“存储过程”,点击鼠标右键,选择“新建存储过程” 第二步:在create PROCEDURE 后 输入存储过程的名字,紧跟着的就是定义存储过程的参数,接下来就可以去编写自己所需要组装的存储过程语句了 第三步: 编译... >>详细
相关问题:用什么工具比较sql server 中 两个存储过程 异同??
答:试试这个《WinMerge 》? >>详细
相关问题:SQL编写存储过程计计算1!+2!+3!+…+N!
答:drop procedure p_test go CREATE procedure p_test(@n int) as begin declare @i int -- 外层循环变量 declare @j int -- 内层循环变量 declare @c varchar(2000) -- 结果字符串 declare @totalc varchar(2000) --内层循环拼接字符串 select @i... >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
