0

I have a SQL query:

SELECT 
      relationId
    , CONVERT(date, receivedDate, 10) AS [Date]
    , matDesc
    , SUM(amount)
    , SKU
FROM 
    tableName
WHERE 
    relationId = 1000
GROUP BY 
      convert(date, receivedDate, 10)
    , relationId
    , matDesc
    , SKU

Which I need to write Dynamically in C# Sqlbuilder. So far I have:

            SelectQuery qry = new SelectQuery("DB");
        qry.WithNoLock = true;
        foreach (ExportColumnDefinition exportColumnDef in GetExportColumnDefinitions())
        {
            qry.SelectColumn(exportColumnDef.DataFieldName);
        }

        qry.Criteria.AddExpressionCriterium("relationId= " + esetting.relationId);
        qry.Criteria.AddColumnCriterium("receivedDate", Operator.GreaterThanOrEqualTo, DateTime.Now.AddDays(-30));
        qry.Criteria.AddColumnCriterium("receivedDate", Operator.LessThanOrEqualTo, DateTime.Now);
        qry.AddOrderByColumn("receivedDate", SortOrder.Descending);

I'm really new to this so I could really use any kind of help or documentation link. (Couldn't find it myself.)

-- Small edit, what I'm missing is: Convert and Sum.


Edit Apparently the SqlBuilder we're using is custom made, so disregard this question.

Paramone
  • 2,634
  • 4
  • 31
  • 58
  • I want to close this question instead of delete, (I am the one asking this), because the SQLBuilder has been made by one of our employees, and couldn't be answered by the comunity. However, I want to keep it open as it may be usefull for some, because of the examples shown. So, small summary: Irrelevant and 'un-answerable', yet it does contain examples which may be of use. Thanks! – Paramone Aug 08 '16 at 12:58

1 Answers1

0

You don't need to make it unnecessary complicated. You can write your query as it is in SqlCommand constructor.

SqlCommand cmd=new SqlCommand("your query", connetionObj); cmd.ExecuteScalar();

Dheeraj Kumar
  • 3,917
  • 8
  • 43
  • 80