May 15, 2010 at 12:52 am
i am using Two textboxes and one button.one textbox is for Fromdate and Another textbox is for Todate.i am selecting
date from textboxes using Ajex calenderExtender.i want to insert every date(Fromdate to Todate) in database on button click.
Example Like.i select 12/30/2010 (MM/DD/YYYY) in FromDate textbox and 01/05/2011 (MM/DD/YYYY) in Todate text box. Now i want to insert
these date
12/30/2010
12/31/2010
01/01/2011
01/02/2011
01/03/2011
01/04/2011
01/05/2011
in database on button click
how to insert eveydate in database?
May 15, 2010 at 5:25 am
what language are you using on your web page? what have you tried so far?
you gave us little information, and the question seems more oriented to the program you are using, and not SQL.
in .net for example, you can set the click to call a server side function which creates a connection, a sqladapter, and calls .ExecuteNonQuery("insert into...)
Lowell
May 15, 2010 at 6:50 am
Instead of passing all those dates to the database to be added in one at a time, why don't you make a stored procedure and pass just the starting and ending dates?
Something like this:
declare @StartDate date ,
@EndDate date
select @StartDate = '20100101',
@EndDate = '20100131'
-- the above lines are to demonstrate this code without being a stored procedure
-- remark out the following line to create the procedure, and then call it
-- with your starting /ending dates.
-- CREATE PROCEDURE dbo.AddDates (@StartDate date, @EndDate date) AS
;WITH
TENS (N) AS (SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL
SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL
SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0),
THOUSANDS (N) AS (SELECT 1 FROM TENS t1 CROSS JOIN TENS t2 CROSS JOIN TENS t3),
MILLIONS (N) AS (SELECT 1 FROM THOUSANDS t1 CROSS JOIN THOUSANDS t2),
TALLY (N) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) FROM MILLIONS)
select @StartDate UNION ALL
select dateadd(day, N, @StartDate)
from Tally
where N <= datediff(day, @STartDAte, @EndDate)
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
May 15, 2010 at 11:51 am
WayneS (5/15/2010)
Instead of passing all those dates to the database to be added in one at a time, why don't you make a stored procedure and pass just the starting and ending dates?
Heh... very well suggested, Wayne. I just got done going through a very similar thing with a client except they were passing a quarter million rows created by the equivalent of a constrained cross join in the GUI. Of course, you know how well cross joins work in SQL Server for the creation of such data. The process went from an 8 minute long data storm on the network to not even a blip on the pipe and something less than 2 seconds on the server.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply