CREATE PROCEDURE spInsertLog
-- Add the parameters for the stored procedure here
    @a    int,
    @b    int,
    @c    int,
    @d    int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @strSQL nvarchar(1024)  -- varchar로 하면 안됨.

    -- Insert statements for procedure here
SET @strSQL = 'INSERT INTO [LOG_'+convert(varchar(4),datepart(yy,getdate()))+
'].dbo.[Log] VALUES (GETDATE(),@paramV1,@paramV2,@paramV3,@paramV4)'

EXEC sp_executesql @strSQL, N'@paramV1 int, @paramV2 int, @paramV3 int, @paramV4 int', @a, @b, @c, @d

END
GO

 

 

 

 

참고.

https://docs.microsoft.com/ko-kr/sql/relational-databases/system-stored-procedures/sp-executesql-transact-sql?view=sql-server-2017

'MSSql' 카테고리의 다른 글

특정 테이블의 컬럼 속성 변경(null, default)  (0) 2021.09.14
update join  (0) 2013.03.07