Results 1 to 3 of 3

Thread: automatically inserting system date on table

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    6

    automatically inserting system date on table

    i have a problem to finishing my work for graduate.. plz give a solution

    i have 1 table : 'period', i'm using MS SQL SERVER 2000. and i want to automatically inserting system date (without sunday) of this month (next month by following the system month) into table 'period' when i click a button on my form.
    example : i input a 25 period in text1.text and i click a 'process' button. i confuse how to automatically take the whole date of this month (without sunday) and inserting them on my 'period' table.

    i need a result like below :

    period total
    11/01/2006 0
    11/02/2006 0
    11/03/2006 0
    11/04/2006 0
    11/06/2006 0 (the date jump to sixth november 2006, cause fifth november is sunday).

    i really appreciate your help.. thank you very much for you advance,

    Serzilq

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: automatically inserting system date on table

    Welcome to the forums.

    What are you building your front end in?

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: automatically inserting system date on table

    This T-SQL - put into a stored procedure - will do what you want...

    Code:
    Declare @StartDate datetime
    Declare @LoopDate datetime
    
    Set @StartDate='2006-10-01'
    Set @LoopDate=@StartDate
    
    While DatePart(mm,@StartDate)=DatePart(mm,@LoopDate)
    Begin
    	If DatePart(dw,@LoopDate)<>1 Insert into SomeTable Values (@LoopDate)
    	Set @LoopDate=DateAdd(dd,1,@LoopDate)
    End
    Do you know how to create and execute stored procedures?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width