/*===========================================================*/ CREATEproceduresp_GenUpdate @TableNamevarchar(130), @PrimaryKeyvarchar(130), @ProcedureNamevarchar(130) as setnocounton declare@maxcolint, @TableIDint 'knowsky.com 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 [email protected]<>'sysname' union select'AS',@maxcol+1ascolorder union select'UPDATE'+@TableName,@maxcol+2ascolorder union select'SET',@maxcol+3ascolorder union selectsyscolumns.name+'=@'+syscolumns.name +casewhencolorder<@maxcolthen',' whencolorder=@maxcolthen'' end astype, colorder+@maxcol+3ascolorder fromsyscolumns joinsystypesonsyscolumns.xtype=systypes.xtype [email protected]<>@PrimaryKeyandsystypes.name<>'sysname' union select'WHERE'+@PrimaryKey+'=@'+@PrimaryKey,(2*@maxcol)+4ascolorder orderbycolorder selecttypefrom#tempprocorderbycolorder droptable#tempproc /*=======源程序结束=========*/ |