Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
dcarroll
Starting Member
3 Posts |
Posted - 2011-08-30 : 09:39:10
|
I am new to SQL and programming in general, and I've found that it is easier to write large queries peicemeal and then combine the code by calling the queries in a main query as I need them. What I'm curious to know is, once I've written my the code this way is there any easy way to combine the smaller queries into one large query? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-30 : 09:43:03
|
depending on your scenario you can use both UNION or JOIN operators for merging your small queries------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
gwilson67
Starting Member
42 Posts |
Posted - 2011-08-30 : 09:46:58
|
Union or Union AllDifference is that Union will remove the duplicates and Union All includes all records including duplicates.Greghttp://www.freewebstore.org/tsqlcoderepositoryPowerful tool for SQL Server development |
|
|
dcarroll
Starting Member
3 Posts |
Posted - 2011-08-30 : 14:22:21
|
the " Main Query"SELECT First(qryTom3.CruiseID) AS FirstOfCruiseID, First(qryTom3.SpeciesID) AS FirstOfSpeciesID, qryTom3.CommonName, First(qryTom3.EventNum) AS FirstOfEventNum1, Avg(IIf(IsNull([TotCt]),0,[TotCt])) AS Mean, StDev(IIf(IsNull([TotCt]),0,[TotCt])) AS StDevFROM qryTom3 LEFT JOIN qryTom1 ON (qryTom3.SpeciesID = qryTom1.SpeciesID) AND (qryTom3.EventNum = qryTom1.EventNum)GROUP BY qryTom3.CommonName; qryTom3SELECT Station.CruiseID, Station.EventNum, Species.SpeciesID, Species.CommonName, Species.SurveySpeciesFROM Species, StationWHERE (((Species.SurveySpecies)="TRUE")); qryTom1SELECT Station.CruiseID, Station.EventNum, CatchSummary.SpeciesID, CatchSummary.TotCtFROM Station INNER JOIN CatchSummary ON Station.EventNum=CatchSummary.EventNum;My problem is that I can't figure out how to compile these queries into a single query |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-31 : 00:20:48
|
are you using sql server? First is not a function in sql serveralso can you show sample data from queries and then how you want to get merged output------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|