I have two SQL queries that query different tables and return similar fields:

```
User - Role - Category - Points

```

and

```
User - Role - Category - Target

```

My queries look like this:

```
select
    acs.UserID,
    acs.RoleID,
    acs.CategoryID,
    sum(acs.Points)
from acs

```

and

```
select
    tb.UserID,
    tb.RoleID,
    tb.CategoryID,
    sum(
        (
            (DATEDIFF(dd, (case when @start >= tb.StartDate then @start else tb.StartDate end), (case when @end <= tb.EndDate then @end else tb.EndDate end)) + 1) 
        ) * tb.dailyMed
    ) as Target
from tb

```

What I would like to end up with is something like this:

```
User - Role - Category - Points - Target

```

Each of the individual queries take less than 1 second to run but when I try to combine them using an inner join it takes over 3 mins to run.

I was hoping there is a more efficient way of doing this but I cannot seem to find one.

\*EDIT
My Inner join looks like this

```
select
    acs.UserID,
    acs.RoleID,
    acs.CategoryID,
    sum(acs.Points),
    t.Target
from
    dbo.ActualCacheSale acs
        inner join
            (select
                tb.UserID,
                tb.RoleID,
                tb.CategoryID,
                sum(
                    (
                        (DATEDIFF(dd, (case when @start >= tb.StartDate then @start else tb.StartDate end), (case when @end <= tb.EndDate then @end else tb.EndDate end)) + 1)
                    ) * tb.dailyMed
                ) as Target
            from
                dbo.TargetBucket tb
            ) t on
                t.UserID = acs.UserID and
                t.RoleID = acs.RoleID and
                t.CategoryID = acs.CategoryID

```