Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC: Best way to create Dynamic Group By
    primarykey
    data
    text
    <p>I got a list of items which can be checked and passed each time differently. The items selected will be moved into a string list containing those checked items.</p> <p>I want to learn a way which will help me create the query required to group by those columns choosen, for example, If i check "OperatorTypeName" and "CompanyName" Ill receive relative query:</p> <pre><code>SELECT OperatorTypeName AS Group1, Company.CompanyName AS Group2, SUM(Adv.Price) AS SumPrice FROM Adv (nolock) INNER JOIN Program (nolock) ON Adv.ProgramID = Program.ProgramID INNER JOIN Operator (nolock) ON Program.OperatorID = Operator.OperatorID INNER JOIN OperatorType (nolock) ON Operator.OperatorTypeID = OperatorType.OperatorTypeID INNER JOIN CampaignVersion (nolock) ON Adv.CampaignVersionID = CampaignVersion.CampaignVersionID INNER JOIN Campaign ON CampaignVersion.CampaignID = Campaign.CampaignID INNER JOIN Campaign2Product (nolock) ON Campaign.CampaignID = Campaign2Product.CampaignID INNER JOIN Product2Company (nolock) ON Product2Company.ProductID = Campaign2Product.ProductID INNER JOIN Product2SubBranch (nolock) ON Product2SubBranch.ProductID = Campaign2Product.ProductID INNER JOIN SubBranch (nolock) ON SubBranch.SubBranchID = Product2SubBranch.SubBranchID INNER JOIN Branch (nolock) ON SubBranch.BranchID = Branch.BranchID INNER JOIN Company (nolock) ON Product2Company.CompanyID = Company.CompanyID INNER JOIN Company Manager (nolock) on Campaign.Manager =Manager.CompanyID WHERE (Adv.TransmitDate &gt;= getdate()-7) GROUP BY OperatorTypeName , Company.CompanyName </code></pre> <p>While if only "OperatorTypeName" will be checked , ill receive the appropriate query for this condition:</p> <pre><code>SELECT OperatorTypeName AS Group1, SUM(Adv.Price) AS SumPrice FROM Adv (nolock) INNER JOIN Program (nolock) ON Adv.ProgramID = Program.ProgramID INNER JOIN Operator (nolock) ON Program.OperatorID = Operator.OperatorID INNER JOIN OperatorType (nolock) ON Operator.OperatorTypeID = OperatorType.OperatorTypeID INNER JOIN CampaignVersion (nolock) ON Adv.CampaignVersionID = CampaignVersion.CampaignVersionID INNER JOIN Campaign ON CampaignVersion.CampaignID = Campaign.CampaignID INNER JOIN Campaign2Product (nolock) ON Campaign.CampaignID = Campaign2Product.CampaignID INNER JOIN Product2Company (nolock) ON Product2Company.ProductID = Campaign2Product.ProductID INNER JOIN Product2SubBranch (nolock) ON Product2SubBranch.ProductID = Campaign2Product.ProductID INNER JOIN SubBranch (nolock) ON SubBranch.SubBranchID = Product2SubBranch.SubBranchID INNER JOIN Branch (nolock) ON SubBranch.BranchID = Branch.BranchID INNER JOIN Company (nolock) ON Product2Company.CompanyID = Company.CompanyID INNER JOIN Company Manager (nolock) on Campaign.Manager =Manager.CompanyID WHERE (Adv.TransmitDate &gt;= getdate()-7) GROUP BY OperatorTypeName </code></pre> <p>I don't want to create every single query for every single condition since I about 30 possible columns i could create a group by with. I might want to call the sql every time there is a bigger query than the last one, but if i've loaded like 10 columns and than i load only 2 of them in next search, ill get to group it from an sessioned query, But lets start with the basics, How can i get it to work without multiple dozens of cases to create every query manually?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload