Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Default Values

Author  Topic 

zai
Starting Member

9 Posts

Posted - 2010-06-07 : 09:36:18
Hello all,

Is there a way for a field to have a value of either 'yes' or 'no' depending on anonther field?

Basically, I have a date field called 'DateDue'. If that date field is less than GetDate, I would like another field to be flagged as 'yes'.

Or perhaps there is another way to do this that is better. Please let me know.

Thank you all so much.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-07 : 10:01:28
select columns,case when DateDue<getdate() then 'yes' else 'no' end as status from table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-06-07 : 11:35:45
As Madhivanan showed, you can simple select the value with that logic. Another option is to make a computed column.
Go to Top of Page

zai
Starting Member

9 Posts

Posted - 2010-06-07 : 11:56:36
You guys are fantastic. Thank you both.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-08 : 02:24:48
quote:
Originally posted by zai

You guys are fantastic. Thank you both.


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -