1

2Dataset ds1 & ds2つの異なるデータを両方とも保持しているとしますTables

Sql1 = "Select sTitle, sDate,active,color FROM TABLE1"
Sql2 = "Select eName, eDate FROM TABLE2"

ds1, ds2これら 2 つを 3 番目のデータセットにマージしds3て、次の列 から取得しEventTitle, BlockedDateたい列を作成する最良の方法は何ですか。sTitle, sDateds1eName, eDateds2

各クエリに最大 200 行が含まれる可能性があることを考慮して、高速なアプローチを知る必要があります。

実際のsql1は

;with Calendar as (
    select EventID, EventTitle, EventStartDate, EventEndDate, EventEnumDays,EventStartTime, EventRecurring, EventStartDate as PlannedDate
    ,EventType from EventCalender
    where EventActive = 1 AND LanguageID =1 AND EventBlockDate = 1 AND(  EventStartDate >= GETDATE() OR EventEndDate >= GETDATE() )
    union all
    select EventID, EventTitle, EventStartDate, EventEndDate, EventEnumDays,EventStartTime, EventRecurring, dateadd(dd, 1, PlannedDate)
    ,EventType from Calendar
    where (EventRecurring = 1
        and dateadd(dd, 1, PlannedDate) <= EventEndDate ) OR (EventRecurring = 0
        and dateadd(dd, 1, PlannedDate) <= EventEndDate) 
)
select EventID, EventStartDate, EventEndDate, PlannedDate as [EventDates], Cast(PlannedDate As datetime) +''+ Cast(EventStartTime As time) AS DT, EventTitle
,EventType from Calendar
where (PlannedDate >= GETDATE()) AND ',' + EventEnumDays + ',' like '%,' + cast(datepart(dw, PlannedDate) as char(1)) + ',%'
    AND PlannedDate <= DATEADD(month, 2, GETDATE())
    or EventEnumDays is null
order by EventID, PlannedDate
option (maxrecursion 0)
4

1 に答える 1

0

を結合するのではなく、またはquery stringを使用して に結合する必要があると思います。joinUniondatatable

于 2012-06-20T07:36:21.793 に答える