Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to insert these dates in database Expand / Collapse
Author
Message
Posted Saturday, May 15, 2010 12:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, May 15, 2010 11:50 AM
Points: 7, Visits: 9
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?
Post #922434
Posted Saturday, May 15, 2010 5:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:33 PM
Points: 12,953, Visits: 32,483
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #922462
Posted Saturday, May 15, 2010 6:50 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:24 PM
Points: 5,370, Visits: 9,009
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
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #922475
Posted Saturday, May 15, 2010 11:51 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:47 PM
Points: 35,770, Visits: 32,436
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
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #922516
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse