Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (4k points)

I have a table test with only one column in it named start_date I want to insert all the dates between two dates for example if I consider 1/7/2014 to 3/7/2014 I need dates as 1/7/2014,2/7/2014,3/7/2014 in my table, but I have problem inserting the code I used is as follows

2 Answers

0 votes
by (8.7k points)

The first step needed to  your code is to start with removing the appropriate errors before moving further as for smooth execution of program.

Below code will help to insert values into the database :

Dim StrSQL As String

Dim InDate As Date

Dim DatDiff As Integer

 

InDate = Me.FromDateTxt

 

StrSQL = "INSERT INTO Test (Start_Date) VALUES ('" & InDate & "' );"

 

DoCmd.SetWarnings False

DoCmd.RunSQL StrSQL

DoCmd.SetWarnings True

0 votes
by (1.2k points)

This query can be resolved using the CTE, in which we have a CTE known as `DateSeries`. This functionality starts with an initial date and then it keeps on adding one day till it reaches the upper bound. Now, we can use a INSERT query over here to take all the dates that are being generated, and then can add the same into the mentioned table

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 18, 2020 in SQL by Appu (6.1k points)
0 votes
4 answers
asked Feb 25, 2021 in SQL by RohitSingh (2.6k points)
0 votes
4 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...