convert sql query to vb.net

khalid mahmood 1 Reputation point
2021-08-13T07:37:08.86+00:00

I have sql query for find missing dates and would like to use in VB.NET , can some help convert query to vb.net and populate missing date in datagrid.

DECLARE  @MaxDate DATE, 
         @MinDate DATE, 
         @iDate  DATE 
-- SQL Server table variable 
DECLARE  @DateSequence TABLE( 
                          DATE DATE 
                          ) 
SELECT @MaxDate = Convert(DATE,Max(DateIn)), 
       @MinDate = Convert(DATE,Min(DateIn)) 
FROM   [Attn]

SET @iDate = @MinDate 

WHILE (@iDate <= @MaxDate) 
  BEGIN 
    INSERT @DateSequence
    SELECT @iDate 

    SET @iDate = Convert(DATE,Dateadd(DAY,1,@iDate)) 
  END 

SELECT Gaps = DATE 
FROM   @DateSequence
EXCEPT 
SELECT DISTINCT Convert(DATE,DateIn) 
FROM   [Attn]
GO 
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,361 questions
{count} votes

2 answers

Sort by: Most helpful
  1. khalid mahmood 1 Reputation point
    2021-08-13T08:42:54.597+00:00

    Yes, table on SQL server
    table: Attn
    Field: DataIn type date

    0 comments No comments

  2. khalid mahmood 1 Reputation point
    2021-08-13T08:45:52.273+00:00

    Date in sql table field

    01/08/2021
    04/08/2021
    06/08/2021
    07/08/2021

    missing dates need to inset in another table

    02/08/2021
    03/08/2021
    05/08/2021

    0 comments No comments