わかりました。2つのテーブルがあります...2つの異なる「会社」を処理するため、そのうちの1つの列名を除いてまったく同じですが、必要なデータは同じ名前の列にあります。私がやりたいことは... tableA.Col2が>0またはtableB.Col2が>0の場合、1..else0..それらも区別する必要があります...別々のテーブルとして取得できます...しかしそれらをまとめることはできません..C3コードページへの送信方法のために1列で必要ですそしてそれをどのように読み取るか...構造はすでに設定されています..そしてこのようなこの1つのストアドプロシージャで実行されている他の約5つのステートメントがあります(これも設定した人ではありませんでした)。ですから、もし可能なら、私に知らせてください。実際のコードを見たいと思ったら、私が持っている正確なコードも貼り付けます。理解しやすくするために、単純化しようとしました。
DECLARE @id INT;
DECLARE @invest nvarchar(50);
SET @id = '7633';
SET @invest = '';
SELECT 'a' + CONVERT(nvarchar, orderfindings.risk_rating) AS cat, COUNT(DISTINCT orderfindings.prnt_id) AS stat
FROM orderheader, orderaudits, orderfindings
WHERE orderheader.id = orderaudits.orderheader_id AND orderaudits.ID = orderfindings.prnt_id
AND orderheader.id = @id AND orderfindings.risk_rating > 0 AND orderaudits.Investor_Name LIKE '%' + @invest + '%'
GROUP BY orderfindings.risk_rating
UNION ALL
SELECT 'a' + CONVERT(nvarchar, orderagencies.risk_rating) AS cat, COUNT(DISTINCT orderagencies.prnt_id) AS stat
FROM orderheader, orderaudits, orderagencies
WHERE orderheader.id = orderaudits.orderheader_id AND orderaudits.ID = orderagencies.prnt_id
AND orderheader.id = @id AND orderagencies.risk_rating > 0 AND orderaudits.Investor_Name LIKE '%' + @invest + '%'
GROUP BY orderagencies.risk_rating
-------------------
/*
Results from 1st statement
cat | stat
-----------
a1 | 4
-----------
a2 | 5
-----------
Results from 2nd statement
cat | stat
-----------
a1 | 3
-----------
a2 | 2
-----------
I pretty much want
Results from new awesome statement
cat | stat
-----------
a1 | 5
-----------
a2 | 5
-----------
I think those are the numbers that would be accurate
Simple version--- if tableA.Col2 is > 0 or tableB.Col2 is > 0 then 1 else 0
|Table A | Table B | result of query
| col_1 col2 | col_1 col2 |
--------------------------------------------------------------------
1 | 1 5 | 1 3 | 1
2 | 1 45 | 1 0 | 1
3 | 1 0 | 1 0 | 0
4 | 1 0 | 1 3 | 1
so a1 would be 3...4 records in the tables..but only 3 of them matter because row 3 has 0
whatevers in col 2 for both tables..there might be 100 records that have 1 for col 1..there
might only be 1
私はこれがもっと理にかなっていることを願っています...それはちょっと奇妙な仕事です