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 |
|
Bobba Buoy
Starting Member
36 Posts |
Posted - 2004-06-25 : 06:13:20
|
I am struggling a little with the best way to write complex queries (the use of parentheses, etc) and when to use stored procedures rather than queries when accessing data using my sql server db.For instance, the following works just fine but can I speed things up if I write it differently?td.TeamID FROM RunTrng rt INNER JOIN PartData pd ON rt.PartID = pd.PartID JOIN TeamData td ON pd.TeamID = td.TeamID WHERE rt.TrngDate >= '5/31/2004' AND rt.TrngDate < '6/25/2004' AND pd.Archive = 'N' AND pd.Grade >= 10 AND pd.Grade <= 12 AND pd.Gender = 'M' AND pd.TeamID <> 86 AND td.Show_Stdgs = 'Y' ORDER BY td.TeamID, rt.PartID I would appreciate any help I can get and any explanations that you would supply with your response.Thanks! |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-06-25 : 06:24:00
|
Parenthesis don't make any difference to the execution unless you change what the query does.You need to look at the execuion plan to see what the query is doing - maybe it's missing a good index.Try formatting like this to make it easier to read. SELECT td.TeamID FROM RunTrng rt JOIN PartData pd ON rt.PartID = pd.PartID JOIN TeamData td ON pd.TeamID = td.TeamID WHERE rt.TrngDate >= '5/31/2004' AND rt.TrngDate < '6/25/2004' AND pd.Archive = 'N' AND pd.Grade >= 10 AND pd.Grade <= 12 AND pd.Gender = 'M' AND pd.TeamID <> 86 AND td.Show_Stdgs = 'Y' ORDER BY td.TeamID, rt.PartID ==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|