select t1.*,t2.hnum as hnum2,t2.hsnum as hsnum,t2.hsqnum as hsqnum2 from Table1 t1 left join Table2 t2 on t1.AddDate=t2.AddDate
------解决方案--------------------
两个查询结果表,再inner join
通过日期字段关联, ------解决方案-------------------- 创建成两张虚拟表,然后用union all拼接
select * from #a
union all
select * from #b ------解决方案--------------------
ALTER PROCEDURE [dbo].[sq_GetInfo]
-- Add the parameters for the stored procedure here
@StartDate datetime,@EndDate datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT distinct a.ProcessId,b.ProcessName into #T
FROM G3_FeedBackBody a left join G0_Process b on a.ProcessId=b.ProcessId order by a.ProcessId
declare @ProcessId varchar(10)
declare cur_SelectData cursor for
select ProcessId from #t
for read only
open cur_SelectData
fetch next from cur_SelectData into @ProcessId
while @@fetch_status=0
begin
select convert(varchar(100),Datelist,23) as AddDate,
isnull(PNum,0) as Hnum,
isnull(SNum,0) as Hsnum,
isnull(SQnum,0) Hsqnum
from (SELECT * FROM DateTable (
@StartDate,@EndDate)) d left join(SELECT convert(varchar(100),a.AddDate,23) as Date,
sum(case when ProcessId=@ProcessId then FNum else 0 end) as PNum,
sum(case when ProcessId=@ProcessId then a.fnum*(b.itemwidth+b.itemheight)*0.0005 else 0 end) as SNum,
sum(case when&nbs