text: Q:
  
  C# & SQL Server improvement
  
  I've got multiple selects from C# to one table in SQL Server in one time period through a stored procedure. That's correct, but that's slow and I'd like to improve that, now.  
  This is my C# code:
  while (startDate!= endDate)
  {
      var anyDay_CntPost = 0;
      anyDay_CntPost = db.GetPostCount(1, tmpDate).Select(x => x.cntPost).FirstOrDefault().Value;
  
      if (anyDay_CntPost != 0)
      {
          var anyDay_cnt1 = db.GetPostCount(1, tmpDate).Select(x => x.cntPost).FirstOrDefault().Value; ;
          var anyDay_cnt2 = db.GetPostCount(2, tmpDate).Select(x => x.cntPost).FirstOrDefault().Value;
          var anyDay_cnt3 = db.GetPostCount(3, tmpDate).Select(x => x.cntPost).FirstOrDefault().Value;
  
          listCount.arr1.Add(anyDay_cnt1);
          listCount.arr2.Add(anyDay_cnt2);
          listCount.arr3.Add(anyDay_cnt3);
      }
  
      startDate = startDate.AddDays(1);
  }
  
  And this is the stored procedure code:
  ALTER PROCEDURE [dbo].[GetPostCount]
      @type int,
      @date nvarchar(max)
  AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
  
      ----<<-----------------------------
      if @type = 1
      begin
          SELECT cntPost = count(*) 
          FROM Post 
          WHERE Date = @date AND type = 1
      end
  
      ---<<------------------------------
      if @type = 1
      begin
          SELECT cntPost = count(*) 
          FROM Post 
          WHERE Date = @date and type = 2
      end
      ---<<------------------------------
      if @type = 2
      begin
          SELECT cntPost = count(*) 
          FROM Post 
          WHERE Date = @date and type = 3
      end
  End
  
  My result is:
  ____________________________________________ 
  |    Date    | Count 1 | Count 2 | Count 3 |  
   ------------------------------------------
  | 10/25/2015 |   200   |  360    |   547   |
  | 10/24/2015 |   185   |  326    |   132   |
  | 10/23/2015 |   100   |  490    |   670   |
   ------------------------------------------
  
  I want optimize the above code, because it's too slow and tardy. What is your suggestion?
  
  A:
  
  My solution would be the following procedure:
  create procedure [dbo].[GetPostCount]
      @startdate date,
      @enddate date
  as
      select Date, Type, count(*) as cntPost
      from Post 
      where Date >= @startdate and Date <= @enddate and Type in (1, 2, 3)
      group by Date, Type
  
  You just select all data that you need once and then use it in your while loop. Now you are querying database 4 times in each iteration and of course it is slow.
  
  