LCNW
asked on
SQL Loop Through Months
I have several values that I need to get on a per month basis making a column for each month.
Rather than doing a DATEPART with a CASE to get through the 12 months I would like to know if there is a function or SQL that could loop through this to reduce my code.
Rather than doing a DATEPART with a CASE to get through the 12 months I would like to know if there is a function or SQL that could loop through this to reduce my code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>"I was hoping to avoid 12 CASE statements."
is 12 case expressions really that bad?
You might be able to use "pivot" (depending on the overall query), but in truth that's not going to be any simpler than those 12 case expressions.
is 12 case expressions really that bad?
You might be able to use "pivot" (depending on the overall query), but in truth that's not going to be any simpler than those 12 case expressions.
ASKER
I have 14 fields so it's 168 CASE statements.
You can generate the CASE statements using system tables, it's not as if you have to type them out yourself :-) .
ASKER
Can you elaborate? Just to clarify, this is MS SQL.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER