none
Linq Equivalent. RRS feed

  • Question

  • SELECT *
    FROM (
      SELECT
        YEAR(OrderDate) [Year],
        CASE MONTH(OrderDate) 
          WHEN 1 THEN 'January'
          WHEN 2 THEN 'February'
          WHEN 3 THEN 'March'
          WHEN 4 THEN 'April'
          WHEN 5 THEN 'May'
          WHEN 6 THEN 'June'
          WHEN 7 THEN 'July'
          WHEN 8 THEN 'August'
          WHEN 8 THEN 'September'
          WHEN 8 THEN 'October'
          WHEN 8 THEN 'November'
          WHEN 8 THEN 'December'
        END as [Month],
        SubTotal
      FROM Sales.SalesOrderHeader
    ) TableDate
    PIVOT (
      SUM(SubTotal)
      FOR [Month] IN (
        [January],[February],[March],[April],
        [May],[June],[July],[August],
        [September],[October],[November],[December]
      )
    ) PivotTable

    can u temme the linq equiv of the above code ?

    Friday, February 24, 2012 10:42 AM

Answers

  • Please try the below. I didn't verified this, please let me know if you face any problem:

    var salesResult = from SOH in Sales.SalesOrderHeader
                     group SOH by new { SOH.[Year] }
                         into yearData
                         select new
                         {
                             yearData.Key.[Year],
    			 Jan = yearData.Where(SOH => SOH.TestVar == "January").Count(),
    			 Feb = yearData.Where(SOH => SOH.TestVar == "February").Count()
    			 .... add the same for all months
                         }

    • Marked as answer by Ind_Alchemist Monday, February 27, 2012 7:05 AM
    Friday, February 24, 2012 1:34 PM

All replies