sql - Making a view change based on year without performance hit -
i have view looks @ 4 recent years. it's pretty complex 18 subqueries. runs fast when years hard coded statement, rather have view changes based on year (school year, actually).
i wrote function grabbed correct year (not current year) , replaced hard coded years, , went <30 seconds more wait. tried selecting correct year, , still didn't finish. tried making ctes containing tables year, , still didn't finish.
i feel that, if variables allowed in view, store year in variable , change hard coded dates (or @var - 1, etc...) , not take performance hit. there way using views without huge execution time increase? or need switch stored procedure?
i haven't done ton of sql i'm still trying figure out if i'm missing here. don't see causing such huge performance change.
thanks.
Comments
Post a Comment