Sunday, March 25, 2012

Calculated field values?

Dear All,

I have a table called CustomerWorkPlan and some of the fields are
1. PlannedID - Primary Key
2. Planned_Start_Date -Datetime field
3. Actual_Start_Date -Datetime field

I wanted to write a query in the from of StoreProcedures which will select some of the

fields and a given field name "Start Date" with the values coming from

Actual_Start_Date if not null else from Planned_Start_Date.

How can I achieve this query? Need help.

create table #tt (plannedid int ,Planned_Start_Date datetime,Actual_Start_Date datetime)
insert into #tt select 1,null,getdate()
insert into #tt select 1,getdate()-1,null

select *,isnull(Actual_Start_Date,Planned_Start_Date)as startdate
from #tt

check this

Madhu

|||

Hi,

is this answer, dear?

Code Snippet

Select PlannedId,

case

when Actual_Start_Date is null then Planned_Start_Date

else Planned_Start_Date

end

from

your table name

|||

masum,

Your suggestion will only provide the Planned_Start_Date -it will never provide the Actual_Start_Date.

Can you see why it is not a correct answer to the question?

No comments:

Post a Comment