USE [UDB_SAMPLE]
GO
/****** Object:  StoredProcedure [dbo].[Sys_TableInfo]    Script Date: 08/15/2009 13:10:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROC [dbo].[Sys_TableInfo]
(
  @TableNm  VarChar(100) = null
  , @Owner Varchar(100) = 'dbo'
)
AS
BEGIN
 SET NOCOUNT ON


 If @TableNm Is Null Or @TableNm = '' Begin
  Print '테이블명을 입력해주세요'
  Return
 End

-- 생성 Sql 문
Declare @Sql_In  NVarchar(4000)
Declare @Sql_In1 NVarchar(4000)
Declare @Sql_In2 NVarchar(4000)
Declare @Sql_Up  NVarchar(4000)
Declare @Sql_Up1 NVarchar(4000)
Declare @Sql_Up2 NVarchar(4000)

Declare @Sql_Declare NVarchar(4000)
Declare @Sql_Declare2 NVarchar(4000)
Declare @Sql_Declare3_1 NVarchar(4000)
Declare @Sql_Declare3_2 NVarchar(4000)
Declare @Sql_Declare3_3 NVarchar(4000)
Declare @Sql_Declare3_4 NVarchar(4000)
Declare @Gubun   char(3)

Declare @Sql_SELECT NVarchar(4000)
Declare @Sql_DELETE NVarchar(4000)

Declare @Sql_NetDao NVarchar(4000)
Declare @Sql_NetDefault NVarchar(4000)
Declare @Int Int
SET @Sql_In = ''
SET @Sql_In1 = ''
SET @Sql_In2 = ''
SET @Sql_Up = ''
SET @Sql_Up1 = ''
SET @Sql_Up2 = ''
SET @Sql_Declare = ''
SET @Sql_Declare2 = ''
SET @Sql_SELECT  = ''


SET @Sql_NetDao = ''
SET @Sql_NetDefault = ''
SET @Int = 1

Declare @ColumnName sql_variant 
Declare @ColumnComment sql_variant 
Declare @ColumnDataType sql_variant 
Declare @ColumnDataLen sql_variant
Declare @ColumnDataLen1 sql_variant
Declare @ColumnDataLen2 sql_variant

Declare @IsIdentity sql_variant 
Declare @IsNullable sql_variant 
Declare @Collation_name sql_variant 
Declare @Definition sql_variant 
Declare @IsPk Int
Declare @IsOutPut Int

Declare @Precision sql_variant 
Declare @Scale  sql_variant

Declare @NetDbType sql_variant


declare @table_name      sysname
declare @table_owner     sysname
declare @table_qualifier sysname
declare @full_table_name    nvarchar(517) -- 258 + 1 + 258


SET @table_owner     = null
SET @table_qualifier = null
SET @table_name = @TableNm
if @table_qualifier is not null
begin
    if db_name() <> @table_qualifier
    begin   -- If qualifier doesn't match current database
        raiserror (15250, -1,-1)
        return
    end
end

if @table_owner is null
begin   -- If unqualified table name
    SELECT @full_table_name = quotename(@table_name)
end
else
begin   -- Qualified table name
    if @table_owner = ''
    begin   -- If empty owner name
        SELECT @full_table_name = quotename(@table_owner)
    end
    else
    begin
        SELECT @full_table_name = quotename(@table_owner) + '.' + quotename(@table_name)
    end
end


   

 


  -- 테이블의 내용을 보기 위한 쿼리....
  SELECT 
    SC.name   ColumnName
   , CCM.VALUE  ColumnComment
   , STY.name  ColumnDataType
   , SC.Max_length ColumnDataLen
   , CASE WHEN SC.is_identity = 1 THEN 'Y' ELSE 'N' END IsIdentity 
   , CASE WHEN SC.is_nullable = 1 THEN 'Y' ELSE 'N' END IsNullable 
   , SC.Collation_name
   , Convert(Varchar,SD.Definition)
   , (Case When Tmp.TABLE_QUALIFIER Is Null and Tmp.PK_NAME Is Null Then 0 Else 1 End) As IsPk 
   , '   '
   , Sc.Precision
   , Sc.Scale
   FROM sys.tables ST 
    INNER JOIN sys.columns SC 
     ON ST.object_id = SC.object_id
    INNER JOIN sys.types STY 
     ON STY.system_type_id = SC.system_type_id 
      AND STY.user_type_id = SC.user_type_id
    LEFT OUTER JOIN ( SELECT major_id, minor_id, VALUE 
         FROM sys.extended_properties
         WHERE class = 1) CCM
     ON SC.object_id = CCM.major_id AND SC.column_id = CCM.minor_id
    LEFT OUTER JOIN (SELECT parent_object_id, parent_column_id, Definition FROM sys.default_constraints) SD
     ON SC.object_id = SD.parent_object_id AND SC.column_id = SD.parent_column_id
    Left Outer Join (
       SELECT
         TABLE_QUALIFIER = convert(sysname,db_name()),
         TABLE_OWNER = convert(sysname,schema_name(o.schema_id)),
         TABLE_NAME = convert(sysname,o.name),
         COLUMN_NAME = convert(sysname,c.name),
         KEY_SEQ = convert (smallint,
          case
           when c.name = index_col(@full_table_name, i.index_id,  1) then 1
           when c.name = index_col(@full_table_name, i.index_id,  2) then 2
           when c.name = index_col(@full_table_name, i.index_id,  3) then 3
           when c.name = index_col(@full_table_name, i.index_id,  4) then 4
           when c.name = index_col(@full_table_name, i.index_id,  5) then 5
           when c.name = index_col(@full_table_name, i.index_id,  6) then 6
           when c.name = index_col(@full_table_name, i.index_id,  7) then 7
           when c.name = index_col(@full_table_name, i.index_id,  8) then 8
           when c.name = index_col(@full_table_name, i.index_id,  9) then 9
           when c.name = index_col(@full_table_name, i.index_id, 10) then 10
           when c.name = index_col(@full_table_name, i.index_id, 11) then 11
           when c.name = index_col(@full_table_name, i.index_id, 12) then 12
           when c.name = index_col(@full_table_name, i.index_id, 13) then 13
           when c.name = index_col(@full_table_name, i.index_id, 14) then 14
           when c.name = index_col(@full_table_name, i.index_id, 15) then 15
           when c.name = index_col(@full_table_name, i.index_id, 16) then 16
          end),
         PK_NAME = convert(sysname,i.name)
         , C.Object_ID
         , C.Column_ID
        FROM
         sys.indexes i,
         sys.all_columns c, 
         sys.all_objects o
        WHERE
         o.object_id = Object_Id(@TableNm) and
         o.object_id = c.object_id and
         o.object_id = i.object_id and
         i.is_primary_key = 1 and
         (c.name = index_col (@full_table_name, i.index_id,  1) or
          c.name = index_col (@full_table_name, i.index_id,  2) or
          c.name = index_col (@full_table_name, i.index_id,  3) or
          c.name = index_col (@full_table_name, i.index_id,  4) or
          c.name = index_col (@full_table_name, i.index_id,  5) or
          c.name = index_col (@full_table_name, i.index_id,  6) or
          c.name = index_col (@full_table_name, i.index_id,  7) or
          c.name = index_col (@full_table_name, i.index_id,  8) or
          c.name = index_col (@full_table_name, i.index_id,  9) or
          c.name = index_col (@full_table_name, i.index_id, 10) or
          c.name = index_col (@full_table_name, i.index_id, 11) or
          c.name = index_col (@full_table_name, i.index_id, 12) or
          c.name = index_col (@full_table_name, i.index_id, 13) or
          c.name = index_col (@full_table_name, i.index_id, 14) or
          c.name = index_col (@full_table_name, i.index_id, 15) or
          c.name = index_col (@full_table_name, i.index_id, 16))
        
        ) As Tmp On Tmp.COLUMN_NAME = SC.name And Tmp.Object_ID = SC.Object_Id And Tmp.Column_Id = SC.Column_Id
   WHERE St.name = @TableNm
 

 

 

 


  -- SELECT / INSERT / UPDATE / Declare 쿼리문을 작성하기 위한 쿼리
 
  Declare myCursor INSENSITIVE cursor
  For


    SELECT c.name
    , type_name(user_type_id) As 'Type'
    , (
      case when (type_name(user_type_id) = 'varchar' or type_name(user_type_id) = 'nvarchar' or type_name(user_type_id) ='char' or type_name(user_type_id) ='nchar')
       then cast(max_length as varchar)
       when type_name(user_type_id) = 'decimal'  
        then cast([precision] as varchar) + ',' + cast(c.scale as varchar) 
      else ''
      end    
     ) As 'Length'
    --, case when is_nullable = 1 then 'Y' else 'N' end 'is_nullable'
    , ( Case When Tmp.Name Is Null Then 0 Else 1 End ) As IsPk
    , c.is_identity
    FROM sys.columns c
       left outer join sys.extended_properties p on p.major_id = c.object_id and p.minor_id  = c.column_id and p.name = 'MS_Description' 
      Left outer Join
      (
      SELECT i.name 
      , col_name(i.object_id, c.column_id) As 'col_name'
      , i.object_id
      FROM sys.indexes i 
       inner join sys.index_columns c on i.index_id = c.index_id and c.object_id = i.object_id 
      WHERE i.name Like 'pk%' 
      And i.object_id  = Object_ID( @Owner + '.' + @TableNm )
      ) As Tmp On Tmp.object_id = c.object_id And Tmp.col_name = c.name 
    --WHERE t.id = @i
     
    WHERE c.Object_id = Object_ID( @Owner + '.' + @TableNm )
    order by c.column_id
   
 

  Open myCursor
  -- Fetch Next FROM myCursor Into @ColumnName , @ColumnDataType , @ColumnDataLen , @IsIdentity , @IsNullable , @Collation_name , @Definition , @IsPk , @Precision , @Scale
  Fetch Next FROM myCursor Into @ColumnName , @ColumnDataType , @ColumnDataLen , @IsPk , @IsIdentity

   while (@@Fetch_Status=0)
    Begin

 

     -- SELECT 쿼리문 작성
     If @Sql_SELECT != '' Begin
      SET @Sql_SELECT = @Sql_SELECT + ','
     End
  
     SET @Sql_SELECT = @Sql_SELECT + Convert(Varchar,@ColumnName)


     -- INSERT 쿼리문 작성
     IF @IsIdentity <> 1 Begin
      If @Sql_In1 = '' Begin
       SET @Sql_In1 = '  '
      End
      Else Begin
       SET @Sql_In1 = @Sql_In1 + char(13) + char(10)+ '  ,'
      End
      
      If @Sql_In2 = '' Begin
       SET @Sql_In2 = '  '
      End
      Else Begin
       SET @Sql_In2 = @Sql_In2 + char(13) + char(10)+ '  ,'
      End
      
      SET @Sql_In1 = @Sql_In1 + Convert(Varchar,@ColumnName)
      SET @Sql_In2 = @Sql_In2 + '@' + Convert(Varchar,@ColumnName)
     End
     
     
     -- Sql UPDATE 쿼리문 작성
     IF @IsIdentity <> 1 Begin
      If @Sql_Up1 = '' Begin
       SET @Sql_Up1 = ' '
      End
      Else Begin
       SET @Sql_Up1 = @Sql_Up1 + char(13) + char(10)+ '  ,'
      End

      SET @Sql_Up1 = @Sql_Up1 + Convert(Varchar,@ColumnName) + ' = @' + Convert(Varchar,@ColumnName)
     End
     
      If @IsPk = 1 Begin
       If @Sql_Up2 != '' Begin
        SET @Sql_Up2 = @Sql_Up2 + char(13) + char(10)+ ','
       End
       SET @Sql_Up2 = @Sql_Up2 + Convert(Varchar,@ColumnName) + ' = @' + Convert(Varchar,@ColumnName)

      End
     
     
     -- Declare 선언문
     If @Sql_Declare != '' Begin
      SET @Sql_Declare = @Sql_Declare + char(13) + char(10)+ ','
     End
     
     IF Convert(Varchar,@ColumnDataLen) = '' Begin
      SET @Sql_Declare = @Sql_Declare + 'Declare @' + Convert(Varchar,@ColumnName) + ' ' + Convert(Varchar,@ColumnDataType)
     End
     Else Begin
      SET @Sql_Declare = @Sql_Declare + 'Declare @' + Convert(Varchar,@ColumnName) + ' ' + Convert(Varchar,@ColumnDataType) + '(' + Convert(Varchar,@ColumnDataLen) + ')'
     End
     

 

     -- Declare 선언문
     If @Sql_Declare2 = '' Begin
      SET @Sql_Declare2 = ' '
     End
     Else Begin
      SET @Sql_Declare2 = @Sql_Declare2 + char(13) + char(10)+ ' ,'
     End
     
     IF Convert(Varchar,@ColumnDataLen) = '' Begin
      SET @Sql_Declare2 = @Sql_Declare2 + '@' + Convert(Varchar,@ColumnName) + ' ' + Convert(Varchar,@ColumnDataType)
     End
     Else Begin
      SET @Sql_Declare2 = @Sql_Declare2 + '@' + Convert(Varchar,@ColumnName) + ' ' + Convert(Varchar,@ColumnDataType) + '(' + Convert(Varchar,@ColumnDataLen) + ')'
     End
 

     Fetch Next FROM myCursor Into @ColumnName , @ColumnDataType , @ColumnDataLen  , @IsPk , @IsIdentity
    End
  Close myCursor
  DeAllocate myCursor

 

 


  -- 프로시져 일때 쿼리문 작성
 
  SET @Int = 1
  Declare myCursor INSENSITIVE cursor
  For    
   SELECT
    param.name AS [Name]
    , ISNULL(baSET.name, N'') AS [SystemType]
    , CAST(CASE WHEN baSET.name IN (N'nchar', N'nvarchar') AND param.max_length <> -1 THEN param.max_length/2 ELSE param.max_length END AS int) AS [Length]
    , CAST(param.precision AS int) AS [NumericPrecision]
    , CAST(param.scale AS int) AS [NumericScale]
    , param.is_output AS [IsOutputParameter] 
    , (case ISNULL(baSET.name, N'') 
     When 'bigint' Then 'SqlDbType.BigInt'
     When 'bit' Then 'SqlDbType.Bit'
     When 'char' Then 'SqlDbType.Char'
     When 'datetime' Then 'SqlDbType.DateTime'
     When 'decimal' Then 'SqlDbType.Decimal'
     When 'float' Then 'SqlDbType.Float'
     When 'image' Then 'SqlDbType.Image'
     When 'int' Then 'SqlDbType.Int'
     When 'money' Then 'SqlDbType.Money'
     When 'nchar' Then 'SqlDbType.NChar'
     When 'ntext' Then 'SqlDbType.NText'
     When 'numeric' Then 'SqlDbType.Decimal'
     When 'nvarchar' Then 'SqlDbType.NVarChar'
     When 'real' Then 'SqlDbType.Real'
     When 'smalldatetime' Then 'SqlDbType.SmallDateTime'
     When 'smallint' Then 'SqlDbType.SmallInt'
     When 'smallmoney' Then 'SqlDbType.SmallMoney'
     When 'text' Then 'SqlDbType.Text'
     When 'timestamp' Then 'SqlDbType.Timestamp'
     When 'tinyint' Then 'SqlDbType.TinyInt'
     When 'uniqueidentifier' Then 'SqlDbType.UniqueIdentifier'
     When 'varbinary' Then 'SqlDbType.VarBinary'
     When 'varchar' Then 'SqlDbType.VarChar'
     When 'xml' Then 'SqlDbType.Xml' 
    Else '' End ) As 'NetDbType'
 
   FROM
   sys.all_objects AS sp
   INNER JOIN sys.all_parameters AS param ON param.object_id=sp.object_id
   LEFT OUTER JOIN sys.types AS baSET ON baSET.user_type_id = param.system_type_id and baSET.user_type_id = baSET.system_type_id
   WHERE
   (sp.type = N'P' OR sp.type = N'RF' OR sp.type='PC')and(sp.name=@TableNm and SCHEMA_NAME(sp.schema_id)=@Owner)
   ORDER BY
   param.parameter_id ASC

 
  Open myCursor
  -- Fetch Next FROM myCursor Into @ColumnName , @ColumnDataType , @ColumnDataLen , @IsIdentity , @IsNullable , @Collation_name , @Definition , @IsPk , @Precision , @Scale
  Fetch Next FROM myCursor Into @ColumnName , @ColumnDataType , @ColumnDataLen , @ColumnDataLen1 , @ColumnDataLen2 , @IsOutPut , @NetDbType

   while (@@Fetch_Status=0)
    Begin
     If @Sql_NetDao != '' Begin
      SET @Sql_NetDao = @Sql_NetDao + char(13) + char(10) 
     End
     
     SET @Sql_NetDao = @Sql_NetDao + 's.SETParameter("' + Convert(Varchar,@ColumnName) + '", "' + Convert(Varchar,@Int) + '", ' + Convert(Varchar,@NetDbType) + ', ' + Convert(Varchar,@ColumnDataLen) + ', ParameterDirection.' + (Case @IsOutPut When 0 Then 'Input' Else  'OutPut' End) + ');'
      
     SET @Int = @Int + 1

     Fetch Next FROM myCursor Into @ColumnName , @ColumnDataType , @ColumnDataLen , @ColumnDataLen1 , @ColumnDataLen2 , @IsOutPut , @NetDbType
    End
  Close myCursor
  DeAllocate myCursor
 


  -- =================================================================
  -- 테이블일경우 SELECT Top 10 을 실행해 컬럼 내용을 볼수 있게 한다.
  If @Sql_SELECT != '' And @Sql_In1 != '' Begin
   Exec  [dbo].[Sys_TableTop10] @TableName = @TableNm
  End

 -- SELECT 쿼리문 작성
 SET @Sql_SELECT = 'SELECT ' + @Sql_SELECT + char(13) + char(10) 
 SET @Sql_SELECT = @Sql_SELECT + 'FROM ' + @TableNm + ' WITH(NOLOCK) ' + char(13) + char(10) 
 SET @Sql_SELECT = @Sql_SELECT + 'WHERE ' + Replace(@Sql_Up2,',',' And ')


 -- INSERT 쿼리문 작성
 --SET @Sql_In = ' INSERT INTO' + @TableNm + '(' + @Sql_In1 +')' 
 --SET @Sql_In = @Sql_In + char(13) + char(10)+ ' VALUES (' + @Sql_In2 +')'

 -- INSERT 쿼리문 작성
 SET @Sql_In = ' INSERT INTO ' + @TableNm + char(13) + char(10) 
 SET @Sql_In = @Sql_In + ' (' + char(13) + char(10) 
 SET @Sql_In = @Sql_In + @Sql_In1 + char(13) + char(10) 
 SET @Sql_In = @Sql_In + ' )' + char(13) + char(10) 
 SET @Sql_In = @Sql_In + ' VALUES' + char(13) + char(10) 
 SET @Sql_In = @Sql_In + ' (' + char(13) + char(10) 
 SET @Sql_In = @Sql_In + @Sql_In2 + char(13) + char(10) 
 SET @Sql_In = @Sql_In + ' )' + char(13) + char(10) 
 

 

 -- UPDATE 쿼리문 작성
 SET @Sql_Up = ' UPDATE ' + @TableNm + ' SET ' + char(13) + char(10) 
 SET @Sql_Up = @Sql_Up + ' '+@Sql_Up1 + char(13) + char(10) 
 SET @Sql_Up = @Sql_Up + ' WHERE ' + Replace(@Sql_Up2,',','  And ')


 -- DELETE 쿼리문 작성
 SET @Sql_DELETE = ' DELETE FROM ' + @TableNm + char(13) + char(10) 
 SET @Sql_DELETE = @Sql_DELETE + ' WHERE ' + Replace(@Sql_Up2,',','  And ')

 Print '/*SELECT 쿼리문....*/'
 Print @Sql_SELECT
 Print char(13) + char(10) 
 Print char(13) + char(10)

 Print '/*INSERT 쿼리문....*/'
 Print @Sql_In
 Print char(13) + char(10) 
 Print char(13) + char(10)

 Print '/*UPDATE 쿼리문....*/'
 Print @Sql_Up
 Print char(13) + char(10) 
 Print char(13) + char(10) 
  
 Print '/*DELETE 쿼리문....*/'
 Print @Sql_DELETE
 Print char(13) + char(10) 
 Print char(13) + char(10) 
  
 Print '/*변수선언문....*/'
 Print @Sql_Declare

 Print char(13) + char(10) 
 Print char(13) + char(10) 
 Print '/*프로시져 변수선언문....*/'
 Print @Sql_Declare2

 
 -- Proc 기본셋팅
 SET @Sql_Declare3_1 = 'USE [UDB_SAMPLE]' + char(13) + char(10)
 SET @Sql_Declare3_1 = @Sql_Declare3_1 + 'GO' + char(13) + char(10)
 
 SET @Sql_Declare3_2 = 'SET ANSI_NULLS ON' + char(13) + char(10)
 SET @Sql_Declare3_2 = @Sql_Declare3_2 + 'GO' + char(13) + char(10)
 SET @Sql_Declare3_2 = @Sql_Declare3_2 + 'SET QUOTED_IDENTIFIER ON' + char(13) + char(10)
 SET @Sql_Declare3_2 = @Sql_Declare3_2 + 'GO' + char(13) + char(10)
 SET @Sql_Declare3_2 = @Sql_Declare3_2 + char(13) + char(10)
 
 SET @Sql_Declare3_3 = @Sql_Declare2 + char(13) + char(10)
 SET @Sql_Declare3_3 = @Sql_Declare3_3 + 'AS' + char(13) + char(10)
 SET @Sql_Declare3_3 = @Sql_Declare3_3 + 'SET XACT_ABORT ON' + char(13) + char(10)
 SET @Sql_Declare3_3 = @Sql_Declare3_3 + char(13) + char(10)
 SET @Sql_Declare3_3 = @Sql_Declare3_3 + 'BEGIN TRY' + char(13) + char(10)
 
 SET @Sql_Declare3_4 = 'END TRY' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + 'BEGIN CATCH' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + ' DECLARE @ErrorMessage NVARCHAR(4000)' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + ' DECLARE @ErrorSeverity INT' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + ' DECLARE @ErrorState INT' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + '' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + '    EXEC USP_ADMINLogError' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + '    SELECT @ErrorMessage = ERROR_MESSAGE(),' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + '           @ErrorSeverity = ERROR_SEVERITY(),' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + '           @ErrorState = ERROR_STATE()' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + '' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + '    RAISERROR ( @ErrorMessage, @ErrorSeverity, @ErrorState )' + char(13) + char(10)
 SET @Sql_Declare3_4 = @Sql_Declare3_4 + 'END CATCH' + char(13) + char(10)
 
 -- Insert Proc 생성
 SET @Gubun = 'INS'
 Print char(13) + char(10) 
 Print char(13) + char(10) 
 Print '/*INSERT 프로시져문....*/'
 print @Sql_Declare3_1
 print '/****** Object:  StoredProcedure ['+@Owner+'].[USP_'+@TableNm+'_'+@Gubun+']    Script Date: '+Convert(varchar(30),GETDATE(),101)+' ******/' + char(13) + char(10)
 print @Sql_Declare3_2
 print 'CREATE PROCEDURE ['+@Owner+'].[USP_'+@TableNm+'_'+@Gubun+']' + char(13) + char(10)
 print @Sql_Declare3_3
 print @Sql_In
 print @Sql_Declare3_4
 Print char(13) + char(10) 
 
 -- Update Proc 생성
 SET @Gubun = 'UPD'
 Print char(13) + char(10) 
 Print char(13) + char(10) 
 Print '/*UPDATE 프로시져문....*/'
 print @Sql_Declare3_1
 print '/****** Object:  StoredProcedure ['+@Owner+'].[USP_'+@TableNm+'_'+@Gubun+']    Script Date: '+Convert(varchar(30),GETDATE(),101)+' ******/' + char(13) + char(10)
 print @Sql_Declare3_2
 print 'CREATE PROCEDURE ['+@Owner+'].[USP_'+@TableNm+'_'+@Gubun+']' + char(13) + char(10)
 print @Sql_Declare3_3
 print @Sql_Up
 print @Sql_Declare3_4
 Print char(13) + char(10) 
 
 -- DELETE Proc 생성
 SET @Gubun = 'DEL'
 Print char(13) + char(10) 
 Print char(13) + char(10) 
 Print '/*DELETE 프로시져문....*/'
 print @Sql_Declare3_1
 print '/****** Object:  StoredProcedure ['+@Owner+'].[USP_'+@TableNm+'_'+@Gubun+']    Script Date: '+Convert(varchar(30),GETDATE(),101)+' ******/' + char(13) + char(10)
 print @Sql_Declare3_2
 print 'CREATE PROCEDURE ['+@Owner+'].[USP_'+@TableNm+'_'+@Gubun+']' + char(13) + char(10)
 print @Sql_Declare3_3
 print @Sql_DELETE
 print @Sql_Declare3_4
 Print char(13) + char(10)

 


 SET @Sql_NetDao = ' using (Statement stm = BaseDAO.GetInstance(this.G_DbCon_Mall).Repository(CommandType.StoredProcedure, "' + @Owner + '.' + @TableNm + '"))
    {
 ' + @Sql_NetDao + '
        IList<IDataParameter> param = s.ExcuteNonQueryOutPut();
    } '

 Print '/*Dao용 Parameters....*/'
 Print @Sql_NetDao

 


 SET NOCOUNT OFF
End

Posted by 김준홍 (http://www.Juuun.com)