How to insert these dates in database

  • 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?

  • 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!

  • 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
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • 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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply