SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to insert these dates in database


How to insert these dates in database

Author
Message
pawantanwar87
pawantanwar87
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 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?
Lowell
Lowell
SSC Guru
SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)

Group: General Forum Members
Points: 153207 Visits: 41543
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
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
WayneS
WayneS
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41306 Visits: 10783
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
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

Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (423K reputation)SSC Guru (423K reputation)SSC Guru (423K reputation)SSC Guru (423K reputation)SSC Guru (423K reputation)SSC Guru (423K reputation)SSC Guru (423K reputation)SSC Guru (423K reputation)

Group: General Forum Members
Points: 423837 Visits: 43406
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search