July 27, 2016 at 11:38 pm
Hi guys,
Hope all are doing good.
I just wanted a idea on report buiding query. Like , i actually tired to bring count for a particular logic , that came well, but when i tried to bring count for another complete different logic in same query it is messed up.
So, can any one tell me idea to merge 2 different logic query in a single result? i mean as seperate column in a single row
for example
result :
col1 col2 col3
logic1 logic2 logic3
I tried Union but some times it works but most of time it gives some problem.
Just give me some sample idea to mingle two different logic in a single row
Thanks
July 28, 2016 at 12:16 am
Can you be more specific about the term "completely different logic"?
Are the tables at least the same for those different logics?
_____________
Code for TallyGenerator
July 28, 2016 at 1:28 am
Sergiy (7/28/2016)
Can you be more specific about the term "completely different logic"?Are the tables at least the same for those different logics?
Thanks for your reply Sergiy, i meant 'completly different logic' because count and grouping them for another set which is in different tables ( no ways to join )
we can use #temp but still i wanted to do it in a query without #temp table. Is there any option that we can combine both in a single row result ?
July 28, 2016 at 1:38 am
JoNTSQLSrv (7/28/2016)
Sergiy (7/28/2016)
Can you be more specific about the term "completely different logic"?Are the tables at least the same for those different logics?
Thanks for your reply Sergiy, i meant 'completly different logic' because count and grouping them for another set which is in different tables ( no ways to join )
we can use #temp but still i wanted to do it in a query without #temp table. Is there any option that we can combine both in a single row result ?
If you are attempting to merge two quite different queries, then why not reduce the number of guesses and post the queries? This article [/url]will help you to understand that forum communication works differently to face-to-face.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 28, 2016 at 10:40 am
Probably the easiest way is to use derived tables within a main query, like below, assuming that each derive table returns only a single row:
SELECT q1.*, q2.*, q3.* --, ...
FROM (
SELECT ..., ...
FROM ...
) AS q1
CROSS JOIN (
SELECT ..., ..., ..., ...
FROM ...
) AS q2
CROSS JOIN (
SELECT ...
FROM ...
) AS q3
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 8, 2016 at 6:37 am
ScottPletcher (7/28/2016)
Probably the easiest way is to use derived tables within a main query, like below, assuming that each derive table returns only a single row:
SELECT q1.*, q2.*, q3.* --, ...
FROM (
SELECT ..., ...
FROM ...
) AS q1
CROSS JOIN (
SELECT ..., ..., ..., ...
FROM ...
) AS q2
CROSS JOIN (
SELECT ...
FROM ...
) AS q3
Thanks a lot ScottPletcher .. it worked
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply