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 |
|
hspatil31
Posting Yak Master
182 Posts |
Posted - 2011-05-27 : 04:57:52
|
| Dear All, I am having followinf query, in that i am getting 1 or more records, through this query i want count of records also and selected columns also.Can anybody please help me how to do this in single query >Query:SELECT INRS.ID AS Normalized_Rate_Sheet_ID, WS.ID as Work_Sheet_ID,Call_Completion, INRS.Rate FROM tb_lcr_international_normalized_rate_sheet INRS INNER JOIN tb_lcr_work_sheet WS ON INRS.Work_Sheet_ID=WS.ID INNER JOIN tb_lcr_rate_sheet RS ON RS.ID=WS.Rate_Sheet_ID INNER JOIN tb_lcr_carrier C ON C.ID=RS.Carrier_ID INNER JOIN tb_lcr_country Coun on COUN.ID=INRS.Country_ID WHERE COUN.Code='33' AND INRS.Dialed_Digits='33' AND INRS.Status=1 AND RS.ID IN(SELECT Rate_Sheet_ID FROM tb_lcr_rate_deck_detail RD INNER JOIN tb_lcr_rate_deck_carrier_rate_sheet RDRSH on RDRSH.Rate_Deck_Details_ID=RD.ID WHERE RD.ID='4D1F1030-62DA-48C8-B24B-4DBEC0073B58') ORDER BY INRS.Rate,C.priority,INRS.Work_Sheet_ID Thanks and Regard'sHarish Patil |
|
|
jfarrugia
Yak Posting Veteran
55 Posts |
Posted - 2011-05-27 : 05:48:23
|
| Hi,If you require an aggregate (COUNT or SUM or AVG etc) of records, this implies that you need to apply the GROUP BY clause to your query which might affect the results. Also, if your selecting, I guess you need to retrieve the actual data not any form of aggregate BUT you also need a countI suggest you split it in two:a) query for selecting - as aboveb) query for aggregates - same as above but alter select to include your COUNT or SUM etc.. and use a GROUP by statementWhere software development knowledge meets the reader |
 |
|
|
|
|
|
|
|