Asp.net 加入2个select查询,与记录数无关
我有两张桌子Asp.net 加入2个select查询,与记录数无关,asp.net,sql-server-2005,Asp.net,Sql Server 2005,我有两张桌子 table 1 table 2 ------------------ ---------------------- description paidamt description recievedamt ele. bill 200 donation 1000 stationary 500
table 1 table 2
------------------ ----------------------
description paidamt description recievedamt
ele. bill 200 donation 1000
stationary 500 fees 200
salary 1000
我想要以下格式的结果(数据将根据日期排序)
问题是,当我将金额设置为借方时,我不能将贷方列设置为空,或者当我将金额设置为相应列的贷方时,我不能将借方列设置为空。我正在进行以下查询
WHEN Payment_Voucher_Master.grand_tot <> '0'
THEN ''
ELSE 'dgf'
END credit
FROM Receipt_Voucher_Master,Payment_Voucher_Master
GROUP BY Payment_Voucher_Master.PaidTo,Payment_Voucher_Master.grand_tot
SELECT Receipt_Voucher_Master.PaidTo
AS description, Receipt_Voucher_Master.grand_total as credit,
CASE
WHEN Receipt_Voucher_Master.grand_total <> '0'
THEN ''
ELSE 'dgf'
END debit
FROM Receipt_Voucher_Master,Payment_Voucher_Master
GROUP BY Receipt_Voucher_Master.PaidTo,Receipt_Voucher_Master.grand_total;
付款\u凭证\u Master.grand\u总计“0”时
然后“
其他“dgf”
终止信用
从收据凭证主控台、付款凭证主控台
按付款凭证主数据集分组。付款凭证主数据集。总数据集
选择收据\u凭证\u主文件.PaidTo
如说明所示,收据、凭证、主记录、总计作为贷方,
案例
当收据\u凭证\u主数据\u总计“0”时
然后“
其他“dgf”
结束借方
从收据凭证主控台、付款凭证主控台
按收据、凭证、主数据、付款到、收据、凭证、主数据、总计分组;
我正在尝试加入这两个查询这应该适合您
SELECT
COALESCE(a.[description],b.[description]) AS [description],
ISNULL(a.[paidamt],'') AS debit,
ISNULL(b.[recievedamt],'') AS credit
FROM [table1] AS a
FULL OUTER JOIN [table2] AS b
ON a.[description] = b.[description]
按照要求给出结果…让我来做。。我会很快回复你的。。感谢qik回复,我已经使用了您的查询,工作很好,只做了一些小的更改,并根据日期进行了排序。。。太多了!!!!按照要求给出结果…让我来做。。我会很快回复你的。。谢谢你的回复
SELECT
COALESCE(a.[description],b.[description]) AS [description],
ISNULL(a.[paidamt],'') AS debit,
ISNULL(b.[recievedamt],'') AS credit
FROM [table1] AS a
FULL OUTER JOIN [table2] AS b
ON a.[description] = b.[description]
declare @table1 table (
[description] varchar(20),
paidamt money
)
declare @table2 table (
[description] varchar(20),
recievedamt money
)
insert @table1 values
('ele. bill',200),
('stationary',500),
('salary',1000)
insert @table2 values
('donation',1000),
('fees',200)
select [description],paidamt as [debit],null as [credit] from @table1
union all
select [description],null as [debit],recievedamt as [credit] from @table2