loops - Looping insert statement in SQL without using cursor -
i have problem looping in sql. want loop startdate until reaches enddate.
they said me not use cursor, found example this:
with mycte ( select cast('2007-01-01' datetime) datevalue union select datevalue + 1 mycte datevalue + 1 < '2030-12-31' ) select * mcte
this works, changed variables situation:
with view_solidnet_training ( select startingdate datevalue union insert obj_availability values(34, datevalue + 1, 'am', 2, 'test') select datevalue + 1 view_solidnet_training datevalue + 1 < endingdate ) select * view_solidnet_training
but following error:
msg 156, level 15, state 1, line 5 incorrect syntax near keyword 'insert'. msg 128, level 15, state 1, line 5 name "datevalue" not permitted in context. valid expressions constants, constant expressions, , (in contexts) variables. column names not permitted. msg 102, level 15, state 1, line 9 incorrect syntax near ')
please try:
with view_solidnet_training ( select @startingdate datevalue union select datevalue + 1 view_solidnet_training datevalue + 1 < @endingdate ) insert obj_availability select 34, datevalue + 1, 'am', 2, 'test' view_solidnet_training
provided @startingdate
, @endingdate
2 date time variables adn table obj_availability
should contain 5 columns in selected order of cte.
Comments
Post a Comment