MONTHLY VARIABLE

I AM WRITING A QUERY THAT WILL NEED TO IDENTIFY VALUES BASED ON THE MONTH.  I HAVE THE BELOW, HOWEVER IS THERE A BETTER WAY TO IDENTIFY THE MONTHLY VALUES

,CASE when OffDte>='2014-02-01' AND OffDte<='2014-02-28' THEN 1
                                ELSE 0 END AS FRESH
Thomask23Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Dude ... all caps?

For starters, make the below change in bold, as <='2014-02-28' will exclude any values of 02-28 after the beginning midnight.  See PortletPaul's article Beware of Between for more info

, CASE when OffDte >= '2014-02-01' AND OffDte  < '2014-03-01' THEN 1 ELSE 0 END AS FRESH

Also, give us some more details on what you mean by 'IDENTIFY THE MONTHLY VALUES', as that could mean a number of different things
0
Mark ElySenior Coldfusion DeveloperCommented:
Use DatePart

DATEPART ( datepart , date )

For month use mm or m

Example
DATEPART (m, '2015-04-24')

Will return 4 for April
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark ElySenior Coldfusion DeveloperCommented:
0
ste5anSenior DeveloperCommented:
For calculating the month as a column use date part. Or even simpley MONTH(OffDte).

E.g. CASE WHEN MONTH(OffDte) = 2 THEN 1 ELSE 0 END AS FRESH.

Or use IIF with SQL Server 2012+.

When you need to filter on that value using  OffDte >= '2014-02-01' AND OffDte  < '2014-03-01' as predicate is better, cause then indices could be used.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.