October 25, 2013 at 3:12 am
I'm a beginner in sql and wonder if this is possible:
Joining these 3 queries together to form a table of results:
declare @sd datetime, @ed datetime, @ac varchar(100), @Theme varchar(100), @Theme2 varchar(100), @IssueType varchar(100)
select distinct Theme from tbl where (nullif(Theme,'') is not NULL) order by Theme asc
select distinct Theme2 from tbl where (nullif(Theme2,'') is not NULL) order by Theme2 asc
select count(1) as NoOfResults from tbl where (ConsentFormReceivedThroughDoor between @sd and @ed)
and(AreaCode = @ac) and(Theme = @Theme) and(IssueType = @IssueType)
October 25, 2013 at 3:23 am
Yes, it's possible, but it depends on what you want it to look like. You first query will return a result set like:
ThemeA
ThemeB
ThemeC
The second will be like:
Theme2A
Theme2B
Theme2C
Theme2D
The third will be like:
7
How do you wish to combine those three result sets? Some sample data and table DDL would be very helpful here.
John
October 25, 2013 at 3:25 am
Also want to note here that the ORDER BY clauses are pretty useless if you want to join results together.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 25, 2013 at 3:26 am
If you have a relation/common columns in a different tables, you can use joins in your query to get the result.
October 25, 2013 at 4:12 am
Theme | Theme2 | NoOfResults
Counting (NoOfResults) how many Theme2s are paired with Theme
October 27, 2013 at 7:40 pm
Retracted due to lack of coffee.
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
November 1, 2013 at 5:29 pm
duncan.turner.2dg (10/25/2013)
Theme | Theme2 | NoOfResultsCounting (NoOfResults) how many Theme2s are paired with Theme
How to relate Theme with Theme2? What is the relationship?
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply