Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Question Regarding Conditional Statement

Status
Not open for further replies.

caper11752

IS-IT--Management
May 6, 2008
26
CA
Hi all,

I need to create a VIEW in SQL 2005 and need some assistance. I'm sure this is possible but it has me stumped. We have a table with several fields, such as Name, StartDate and EndDate. I need the VIEW to return Name, and another field with either True or False in it. So if the difference between StartDate and EndDate is less than 365 days then TRUE, else FALSE.

Thanks if advance
 
[tt][blue]
Create View YourViewName
As
Select Name,
Case When DateDiff(day, StartDate, EndDate) > 365
Then Convert(Bit, 0)
Else Convert(Bit, 1)
End As AliasName
From YourTable
[/blue][/tt]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Look at DATEDIFF function Help in BOL.
Code:
Select Name, cast(case when datediff(day, EndDate, StartDate) <365 then 1 else 0 end) as bit) as IsLessThanYear from myTable
 
Every time I click on reply and submit on a new post I see 2 replies and it has to be either George or Boris.
 
BTW, I forgot to put Name in [], e.g.

select [Name], ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top