SQL Server 2005 derived field w/ logic -


i have 3 tables pproject, projectmilestone , releaseschedule.

i want add derived field project table called enddate.

the value of new field called enddate should larger of 2 values projectmilestone.enddate , releaseschedule.enddate.

the sql logic 2 data points of enddate within both tables this:

select enddate projectmilestone milestonecid = 77 , projectid = project.projectid

select enddate releaseschedule milestonecid = 77 releaseid = project.releaseid

so need derived field larger of these 2 values , if neither value exist have 'n/a'

i @ point trying case statement work...

alter table project add enddate (case when projectmilestone.enddate < releaseschedule.enddate projectmilestone.enddate else releaseschedule.enddate end)

how n/a if both null?

thanks all

this sort of thing better handled in client application, can in t-sql below.

all outputs case statement have of same data type have cast dates char or varchar.

alter table project  add enddate  isnull((case    when projectmilestone.enddate < releaseschedule.enddate      cast(projectmilestone.enddate varchar(50))   else      cast(releaseschedule.enddate varchar(50))    end), 'n/a') 

alternatively, use convert instead of cast , specify date style prettier dates.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -