Nate Pet
Nate Pet

Reputation: 46222

sql server DATEADD with sql inside DATEADD

I need to do the following:

    Select ProID from Pros ps where ps.ProId = '102-C01-1299'
    and  ConfirmDate > DATEADD(DAY, (select tt.DaysDue from tblTaskTimeline tt where Task   = 'TaskInfo') as days,ps.ProgStartDate) 

Note how for the DATEADD function, I need to dynamically get the 2nd parameter. Note that tt.DaysDue returns an integer value.

I get a message saying that DATEADD requires 3 parameters.

Upvotes: 1

Views: 1679

Answers (2)

suff trek
suff trek

Reputation: 39767

Remove " as days" and it should work.

Upvotes: 0

Taryn
Taryn

Reputation: 247650

Why not just create a parameter first?

declare @days int
set @days = (select tt.DaysDue from tblTaskTimeline tt where Task   = 'TaskInfo')

Select ProID 
from Pros ps 
where ps.ProId = '102-C01-1299'
    and  ConfirmDate > DATEADD(DAY, @days, ps.ProgStartDate)

If you cannot use a parameter then the following should work:

Select ProID 
from Pros ps 
where ps.ProId = '102-C01-1299'
    and  ConfirmDate > DATEADD(DAY, (select tt.DaysDue from tblTaskTimeline tt where Task = 'TaskInfo'), ps.ProgStartDate)

Upvotes: 1

Related Questions