SQL에서 반복 문제가 있습니다. 종료 날짜에 도달 할 때까지 시작 날짜를 반복하고 싶습니다. 커서를 사용하지 않고 SQL에서 삽입 문을 반복합니다.
그들은 커서를 사용하지 않는 나에게 말했다, 그래서 나는이 같은 예를 발견 이with mycte as
(
select cast('2007-01-01' as datetime) DateValue
union all
select DateValue + 1
from mycte
where DateValue + 1 < '2030-12-31'
)
select * from mcte
이 작품을, 그래서 난 내 상황 변수를 변경 :
with View_Solidnet_Training as
(
select StartingDate as DateValue
union all
insert into OBJ_Availability values(34, DateValue + 1, 'AM', 2, 'Test')
select DateValue + 1
from View_Solidnet_Training
where DateValue + 1 < EndingDate
)
select * from View_Solidnet_Training
하지만
Msg 156, Level 15, State 1, Line 5 Incorrect syntax near the keyword 'insert'. Msg 128, Level 15, State 1, Line 5 The name "DateValue" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. Msg 102, Level 15, State 1, Line 9 Incorrect syntax near ')
그리고 오류는 무엇입니까? –
메시지 156, 수준 15, 상태 1, 줄 5 'insert'키워드 근처의 구문이 잘못되었습니다. 메시지 128, 수준 15, 상태 1, 줄 5 "DateValue"라는 이름은이 컨텍스트에서 허용되지 않습니다. 유효한 표현식은 상수, 상수 표현식 및 (일부 컨텍스트에서) 변수입니다. 열 이름은 허용되지 않습니다. 메시지 102, 수준 15, 상태 1, 줄 9 ')'근처에 구문이 잘못되었습니다. – user2206834
중요한 정보를 의견으로 게시하지 마십시오. 질문 편집 –