The best way to achieve that is to
create stored procedure[
^] on SQL server level. See an SQL code sample.
USE YourDateBaseName;
CREATE PROCEDURE uspInsertDateRange
@startDate DATE,
@endDate DATE,
@myVal INT
AS
SET NOCOUNT ON;
;WITH CTE AS
(
SELECT @startDate AS myDate, @myVal AS myValue
WHERE @startDate <= @endDate
-recursion part
UNION ALL
SELECT DATEADD(DD, 1, myDate) AS myDate, @myVal AS myValue
FROM CTE
WHERE DATEADD(DD, 1, myDate) <= @endDate
)
INSERT INTO YourTableName (myDate, myValue )
SELECT myDate, myValue
FROM CTE
OPTION (MAXRECURSION 0)
GO;
How to call it from code? Check this:
How to: Set and Get Parameters for Command Objects[
^]
In case you want to use a UI to achieve that, you'll need to create
DataTable[
^] and
SqlBulkCopy Class (System.Data.SqlClient)[
^]
Try!