Guest User

Guest User

  • Tech Writer
  • 15
  • 6.2k

SQL to LINQ Conversion

Feb 8 2019 2:45 AM
Hello.. I'm new to LINQ to SQL using C#. I am wondering if this Query is convertable to LINQ ?
 
 
  1. SET @cnt = 0;  
  2. SET @Company = @CompCode  
  3.   
  4. select TOP 1 @cdate = convert(date,DateReleased) from IRForm WHERE Company = @Company  
  5. set @cdate = (select TOP 1 convert(date,DateReleased) from IRForm WHERE Company = @Company)  
  6.   
  7. select TOP 1 @cnt = COUNT(Company) from IRForm WHERE Company = @Company AND convert(date,@cdate) = convert(date,@dn)  
  8. set @cnt = (select TOP 1 COUNT(Company) from IRForm WHERE Company = @Company AND convert(date,@cdate) = convert(date,@dn))  
  9.   
  10.   
  11.   
  12.                 IF (@cnt = 0)  
  13.                     BEGIN                     
  14.                         INSERT INTO IRForm (  
  15.                         IR_No,  
  16.                         Subj_Desc,  
  17.                         Subj_Code,  
  18.                         Company,  
  19.                         Incident_Date,  
  20.                         Reported_By,  
  21.                         Mpad_SN,  
  22.                         User_No,  
  23.                         A_S_B,  
  24.                         Person_Involved,  
  25.                         DT_Recieved,  
  26.                         Incident_Desc,  
  27.                         OS_Name,  
  28.                         OS_Submitted)  
  29.   
  30.   
  31.                         VALUES (  
  32.                         @Company + FORMAT( @dn, 'yy/MM/''en-US' ) + '00' + CAST(@cnt + 1 as varchar(10)),  
  33.                         @Subj_Desc,  
  34.                         @Subj_Code,  
  35.                         @Company,  
  36.                         @Incident_Date,  
  37.                         @Reported_By,   
  38.                         @Mpad_SN,  
  39.                         @User_No,  
  40.                         @A_S_B,  
  41.                         @Person_Involved,  
  42.                         @DT_Recieved,  
  43.                         @Incident_Desc,  
  44.                         @OS_Name,  
  45.                         @OS_Submitted)  
  46.                     END  
 If yes, please provide me an example so that I can continue learning LINQ. Thank you C# Corner.

Answers (2)