Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:57:42+00:00 2026-06-04T17:57:42+00:00

I am on my first week of a summer programming internship and have been

  • 0

I am on my first week of a summer programming internship and have been tasked with converting SQL Server 2008 statements into C# using LINQPad. Once I do that and get it working properly, I can enter it into VS and tweak as needed.

The problem is that I am running across SQL statements I have no idea how to convert. In my C# class we did not convert SQL statements into C#, we just created a string variable, assigned the SQL statement to variable and then assigned the variable to an OleDbCommand object. My mentor took the day off for the long weekend and I’m pretty much on my own and clueless on what to do and need some help. There are a couple of dozen like this one and if I can see how to do one I can figure the rest out. Here is the SQL statement:

,[hrs].{Hours] - SUM(
  CASE 
    WHEN [UnitState].[UnitStateTye] <> 'ACTIVE' 
      THEN [Allocation].[AllocatedEnergyMwh] 
    ELSE 0 
  END 
/ CAST([Unit].[NetDependableCapacity] AS FLOAT)) AS SH

I’m pretty sure this is an if statement along the lines of:

if [UnitState].[UnitStateType] does not equal active 
then SH equals [hrs].[Hours] minus the the sum of
  [Allocation].[AllocatedEnergyMwh] / (float)[Unit].[NetDependableCapacity].  
else 
  SH = [hrs].[Hours]

I tried the following code, which I figured wasn’t going to work but needed to start somewhere:

var results = 

    (from v in VDimUnit     
        join vf in VFactEnergyAllocation on v.UnitKey equals vf.UnitKey
        join vd in VDimGadsEvent on vf.GadsEventKey equals vd.GadsEventKey
        join vt in VDimTime on vf.TimeKey equals vt.TimeKey 
        join vus in VDimUnitState on vf.UnitKey equals vus.UnitKey
    where vd.GadsEventEndTime.Year == 2011 && v.UnitId == "THL3"
    group vf by new {vus.UnitStateType, vf.AllocatedEnergyMwh v.NetDependableCapacity,
        vt.QuarterNum} into groupItem       
    select new {groupItem.Key.QuarterNum, SUM1 = groupItem.Sum(x=> (float)x.AllocatedEnergyMwh /
        groupItem.Key.NetDependableCapacity)}).ToArray();

var resultHours = 
    (from v in VDimTime
    group v by v.QuarterNum into groupItem
    select new {Hours = groupItem.Count(), groupItem.Key}).ToDictionary(x=> x.Key, x=> x.Hours);

var finalResults = 
    (from r in results
    select new {SH_IF_NOT_ACTIVE = resultHours[r.QuarterNum] - r.SUM1,
        Hours = 
        SH_IF_ACTIVE = resultHours[r.QuarterNum]});

    if (SH != "ACTIVE")
    { 
        SH_IF_NOT_ACTIVE;
    }
    else
    {
        SH_IF_ACTIVE;
    }   

I would appreciate it is someone could point me in the right direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:57:43+00:00Added an answer on June 4, 2026 at 5:57 pm

    Something like this:

    Hours = condition ? code when true : code when false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first week teaching myself javascript and i have run into a
I am into my first week of DDD and have a couple of entities
This is the first week I've been playing with jQuery so I have a
Suppose I have 2011-01-03 and I want to get the first of the week,
I have the following expression within a report: = Switch( Fields!RATE_CODE.Value = First, £/Week,
I have a method that returns the first day of the first week of
Our project has been using Git for a week or so now, and we're
What is the first day of the week in mysql, Monday or Sunday?? I
I am currently getting first day Of this week and last week values with
How can I get first and last days of the current week? What I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.