0

表结构如下:

Sales: Sales_id, sDate,ccode,qty,amt;     
Challan: Ch_id, ch_date,qty,amt;

所需资料为:

Id | Date | CCode | Type | Qty | Amt

If sales then type = sales; if challan then type = challan ; order by date

我尝试了以下方法:

select s.cust_code,s.cust_name,s.sales_qty,s.sales_amt,c.cust_code,
c.cust_name,c.challan_qty ,c.challan_amt 
from sales s inner 
join challan c on s.sales_date  = c.challan_date

我应该如何放置自定义类型的列并在特定日期显示挑战或销售?

4

1 回答 1

2

看来您正在寻找联合声明:

select 
  Sales_id as Id, sDate as [date], ccode as CCode, 
  'sales' as Type, qty as Qty, amt as Amt
From Sales
Union
select
  Ch_id as Id, ch_date as [date], Null as CCode, 
  'Challan' as Type, qty as Qty, amt as Amt
from Challan
于 2013-08-23T14:44:13.217 回答