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 |
javauser
Starting Member
3 Posts |
Posted - 2008-08-13 : 13:56:51
|
The concerned query is the last one.And DQ1,DQ2 are the first and second queriesSELECT estats.ID, eparams.Parameter as [SC], eprms.ParamValue as [SrcCode]FROM eparams INNER JOIN (eprms INNER JOIN estats ON eprms.ID = estats.ID) ON eparams.ParamID = eprms.ParamIDWHERE (((eparams.Parameter)="srcCode"))ORDER BY estats.ID, eparams.Parameter, eprms.ParamValue;SELECT estats.ID, eparams.Parameter as [Don], eprms.ParamValue as [DonAmt]FROM eparams INNER JOIN (eprms INNER JOIN estats ON eprms.ID = estats.ID) ON eparams.ParamID = eprms.ParamIDWHERE (((eparams.Parameter)="donAmt"))ORDER BY estats.ID, eparams.Parameter, eprms.ParamValue;select SC_NAMES.SC_Name as [Source],first(DQ1.SrcCode) as [Source Code],count(DQ1.[estats.ID]) as [Number of Donations],sum(DQ2.DonAmt) as [Donation Amount]FROM (@Datalink.Query(1).Name@ DQ1 INNER JOIN @Datalink.Query(2).Name@ DQ2ON DQ1.id=DQ2.id) LEFT OUTER JOIN SC_NAMES ON Mid(DQ1.SrcCode,1,2) = SC_NAMES.SC_CODEGroup By DQ1.SrcCode |
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
javauser
Starting Member
3 Posts |
Posted - 2008-08-13 : 14:58:48
|
Hi,Sorry the information got cropped up.The below sql query which works correctly.But it only displays the value 'source' only once eventhough when the same value appears more than once.How can I make it to print for each and every value.I tried to remove 'first' clause for source column an error occurs asYou tried to execute a query that does not include the specified expression 'Source' as part of an aggregate function.The concerned query is the last one.And DQ1,DQ2 are the first and second queries SELECT estats.ID, eparams.Parameter as [SC], eprms.ParamValue as [SrcCode]FROM eparams INNER JOIN (eprms INNER JOIN estats ON eprms.ID = estats.ID) ON eparams.ParamID = eprms.ParamIDWHERE (((eparams.Parameter)="srcCode"))ORDER BY estats.ID, eparams.Parameter, eprms.ParamValue;SELECT estats.ID, eparams.Parameter as [Don], eprms.ParamValue as [DonAmt]FROM eparams INNER JOIN (eprms INNER JOIN estats ON eprms.ID = estats.ID) ON eparams.ParamID = eprms.ParamIDWHERE (((eparams.Parameter)="donAmt"))ORDER BY estats.ID, eparams.Parameter, eprms.ParamValue;select SC_NAMES.SC_Name as [Source],first(DQ1.SrcCode) as [Source Code],count(DQ1.[estats.ID]) as [Number of Donations],sum(DQ2.DonAmt) as [Donation Amount]FROM (@Datalink.Query(1).Name@ DQ1 INNER JOIN @Datalink.Query(2).Name@ DQ2ON DQ1.id=DQ2.id) LEFT OUTER JOIN SC_NAMES ON Mid(DQ1.SrcCode,1,2) = SC_NAMES.SC_CODEGroup By DQ1.SrcCode |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-08-13 : 15:19:55
|
You need to add SC_NAMES.SC_Name to the GROUP BY if you want to include that column in the results.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
javauser
Starting Member
3 Posts |
Posted - 2008-08-14 : 10:28:16
|
I have modified the query as below but it output remains same.Eventhough I tried using 'First' as first(SC_NAMES.SC_Name),first(DQ1.[SrcCode]) the output remains same let me know what more modification the query needsselect (SC_NAMES.SC_Name) as [Source],first(DQ1.[SrcCode]) as [Source Code],count(DQ1.[estats.ID]) as [Number of Donations],sum(DQ2.DonAmt) as [Donation Amount]FROM (@Datalink.Query(1).Name@ DQ1 INNER JOIN @Datalink.Query(2).Name@ DQ2ON DQ1.id=DQ2.id) LEFT OUTER JOIN SC_NAMES ON Mid(DQ1.SrcCode,1,2) = SC_NAMES.SC_CODEGroup By DQ1.SrcCode,SC_NAMES.SC_Name |
 |
|
|
|
|
|
|