Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Is this possible? Expand / Collapse
Author
Message
Posted Friday, October 25, 2013 3:12 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 1, 2014 2:09 AM
Points: 4, Visits: 13
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)

Post #1508373
Posted Friday, October 25, 2013 3:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 5,386, Visits: 9,962
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
Post #1508377
Posted Friday, October 25, 2013 3:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 8:15 AM
Points: 13,017, Visits: 10,800
Also want to note here that the ORDER BY clauses are pretty useless if you want to join results together.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1508379
Posted Friday, October 25, 2013 3:26 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, December 12, 2013 3:41 AM
Points: 5, Visits: 42
If you have a relation/common columns in a different tables, you can use joins in your query to get the result.
Post #1508380
Posted Friday, October 25, 2013 4:12 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 1, 2014 2:09 AM
Points: 4, Visits: 13
Theme | Theme2 | NoOfResults

Counting (NoOfResults) how many Theme2s are paired with Theme
Post #1508395
Posted Sunday, October 27, 2013 7:40 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 3:30 AM
Points: 3,420, Visits: 5,348
Retracted due to lack of coffee.


My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1508730
Posted Friday, November 1, 2013 5:29 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, April 1, 2014 6:12 PM
Points: 827, Visits: 342
duncan.turner.2dg (10/25/2013)
Theme | Theme2 | NoOfResults

Counting (NoOfResults) how many Theme2s are paired with Theme


How to relate Theme with Theme2? What is the relationship?
Post #1510830
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse