sql server - Create variable name from while loop value SQL -
first time poster on site , need advice: is possible declare/create new variable base on while loop? context: financial calendar company assigns each date within financial year period (month) , week number. these can change each year depending on date of new financial year. i want create function runs while loop week , period number specified date. i want able along lines of while > @enddate if date between such , such week = @w(i) end i not sure how explain it. i have function listing week , period numbers looks messy , not efficient. can advise? thank you edit: apologies my code in sql server. what have far messy , complete draft i'll pop in here now. declare @startdate datetime , @enddate datetime , @thisdate datetime , @p1 datetime , @p2 datetime , @p3 datetime , @p4 datetime --and forth until p12 , @w1 datetime , @w2 datetime , @w3 datetime , @w4 datetime , @w5 datetime --and forth until w52 set @startdate = ...