arkam chou
asked on
SQL Two column as ones
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nice picture. btw Next time do us a favor and capture a screenshot of your diagram, and use the Image button to post it. That way we can see your picture and question in one view without having to click back and forth. Thanks in advance.
ASKER
Give this a whirl..
SELECT DateIssue, Name, number, price
FROM (
SELECT DateA as DateIssue, Name, number, NULL as price
FROM tblA
UNION ALL
SELECT DateB, Name, NULL, price
FROM tblB)
WHERE number=10 OR price=200
When using large sets, I would use:
Cause imho there is no predicate push-down in this case.
SELECT DateA AS DateIssue ,
Name ,
number ,
NULL AS price
FROM tblA
WHERE number = 10
UNION ALL
SELECT DateB ,
Name ,
NULL ,
price
FROM tblB
WHERE price = 200;
Cause imho there is no predicate push-down in this case.
ASKER
Hello All,
@Jim Horn: I saw in MSSQL said that "incorrect syntax. when put mouse hover on "DateIssue", it said that "invalide column name. what should to do?
@ste5an: I need to put some condition after select.
ex: order by name
@Jim Horn: I saw in MSSQL said that "incorrect syntax. when put mouse hover on "DateIssue", it said that "invalide column name. what should to do?
@ste5an: I need to put some condition after select.
ex: order by name
Just use a sub-query as Jim did.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes, it work but I have problem with "Null" display in column "price" and "number". How can I use "group by" and "sum" on this query?
SELECT DateIssue ,
Name ,
sum(number) ,
sum(price)
FROM ( SELECT DateA AS DateIssue ,
Name ,
number ,
NULL AS price
FROM tblA
UNION ALL
SELECT DateB ,
Name ,
NULL ,
price
FROM tblB
) Q
group by dateissue, name
WHERE number = 10
OR price = 200;
GROUP BY must be placed after the WHERE clause.
ASKER
yes, it work. one more thing how to change from "null" value to "0" value?
ASKER
ok. now it work with "ISNULL(null, 0)".
ASKER
Thanks you all for you support.
Open in new window