2016-11-14 2 views
0

안녕하세요 내가 문제를 가지고SQL 삽입 및 매개 변수

declare @target_date datetime 
set @target_date=GETDATE(); 


insert into table1 ([column1],[column2],[column3]) 
(select [column1],[column2] from table2 where [email protected]), @target_date 

나는이 문제

에게 삽입을 해결할 수있는 방법
Table1.Column1 = Table2.Column1
Table1.Column2 = 표 2 .Column2
[email protected]_date

답변

1
declare @target_date datetime 
set @target_date=GETDATE(); 


insert into table1 ([column1],[column2],[column3]) 
select [column1],[column2], @target_date from table2 where [email protected] 

변수를 계산 된 열의 값으로 변경하십시오.

0

삽입 후 select 명령에는()을 (를) 할 필요가 없으며 select 명령 내에서 @target_date를 이동해야합니다.

+0

기술적으로는 내가 이미 그렇게 대답했지만 기술적으로 정확할 것입니다. 앞으로는 코드를 통해 실제 변경 내용을 표시하는 것이 좋을 것입니다. 즉, 직접적인 서술이 아닌 다른 사람들이 귀하의 대답을 그렇게 쉽게 따르는 것이 더 쉽습니다. – Matt