Results 1 to 8 of 8

Thread: Create default

  1. #1
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    98

    Unanswered: Create default

    Hi All,

    Can someone tell me how to create a default that put the current date into a record on insert and current date + 1 year into another record!?

    Cheers Wimmo

  2. #2
    Join Date
    Feb 2004
    Location
    INDIA, CHENNAI
    Posts
    7

    Re: Create default

    use getdate() in the field where date field is used in insert.

  3. #3
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    98

    Re: Create default

    Originally posted by nhariharan
    use getdate() in the field where date field is used in insert.
    I tried it, but i keeps the null value.

  4. #4
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Code:
    use pubs
    go
    create table #abc
    (
    	fname varchar(10),
    	joindate datetime default getdate(),
    	joinyear int default datepart(yyyy,getdate())
    )
    go
    insert into #abc
    (
    	fname
    )
    select 
    	'Enigma' 
    go
    select 
    	* 
    from 
    	#abc
    go
    drop table #abc
    go
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  5. #5
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    98
    Originally posted by Enigma
    Code:
    use pubs
    go
    create table #abc
    (
    	fname varchar(10),
    	joindate datetime default getdate(),
    	joinyear int default datepart(yyyy,getdate())
    )
    go
    insert into #abc
    (
    	fname
    )
    select 
    	'Enigma' 
    go
    select 
    	* 
    from 
    	#abc
    go
    drop table #abc
    go
    Thanx the getdate() works.
    I use 2 columns 1 named join date and 1 named enddate ,standard users get 1 year acces to the application so when a new user register the enddate must be automatically set 1 year after the joindate,
    do you know how to manage that?

    Thanx already.

    Cheers Wim

    I

  6. #6
    Join Date
    Jan 2003
    Location
    India
    Posts
    523
    Originally posted by Wimmo
    Thanx the getdate() works.
    I use 2 columns 1 named join date and 1 named enddate ,standard users get 1 year acces to the application so when a new user register the enddate must be automatically set 1 year after the joindate,
    do you know how to manage that?

    Thanx already.

    Cheers Wim

    I
    create table #abc
    (
    fname varchar(10),
    joindate datetime default getdate(),
    Enddate datetime default dateadd(yy,1,getdatE())
    )

  7. #7
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    98
    Originally posted by harshal_in
    create table #abc
    (
    fname varchar(10),
    joindate datetime default getdate(),
    Enddate datetime default dateadd(yy,1,getdatE())
    )
    I tried this but the result seems strange:

    joindate 13-2-2004 11:48:45 enddate Feb 13 200

  8. #8
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Originally posted by Wimmo
    I tried this but the result seems strange:

    joindate 13-2-2004 11:48:45 enddate Feb 13 200
    create table #abc
    (
    fname varchar(10),
    joindate datetime default getdate(),
    endate datetime default dateadd(yy,1,getdate())
    )
    go
    insert into #abc
    (
    fname
    )
    select
    'Enigma'
    go
    select
    *
    from
    #abc
    go
    drop table #abc
    go
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

Posting Permissions

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