default column

  • i am having a problem setting default column.

    i want to set it like getdate()

    what i want to set is the default year

    when ever a new record is inserted it should store its year

    so i wrote year(getdate()), but its getting changed to datepart(year,getdate())

    Silly is n't it ??

    what shall i do

    <a href="http://www.websolsoftware.com"> For IT jobs click here</a>

    *Sukhoi*[font="Arial Narrow"][/font]

  • pls ppl answer me,this is very imp for me

    because iam going to set composite primary key

    base on

    invoice_no

    invoice_type

    Year ( year is having problem)

    year will have default value, and i have written default to be

    select year(getdate())

    but its not working??

    <a href="http://www.websolsoftware.com"> For IT jobs click here</a>

    *Sukhoi*[font="Arial Narrow"][/font]

  • now iam getting default value as this..

    ??

    select year(getdate())

    what to do about this.

    <a href="http://www.websolsoftware.com"> For IT jobs click here</a>

    *Sukhoi*[font="Arial Narrow"][/font]

  • but its getting changed to datepart(year,getdate())

    What's so stupid about this???

    
    SET NOCOUNT ON
    CREATE TABLE year_t
    (
    year_now INT DEFAULT DATEPART(year,GETDATE())
    )
    INSERT INTO year_t DEFAULT VALUES
    SELECT * FROM year_t
    DROP TABLE year_t
    SET NOCOUNT OFF
    
    
    year_now    
    ----------- 
    2004
    

    Isn't that what you want?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • yes thats what i wanted, and i did it that way only.

    but my

    select year(getdate())

    was also working in my local database but its not working on the main server.

    how come.

    <a href="http://www.websolsoftware.com"> For IT jobs click here</a>

    *Sukhoi*[font="Arial Narrow"][/font]

  • You mean something liek this

    SET NOCOUNT ON
    CREATE TABLE year_t
    (
    year_now INT DEFAULT SELECT DATEPART(YEAR, GETDATE()) --DATEPART(year,GETDATE())
    )
    INSERT INTO year_t DEFAULT VALUES
    SELECT * FROM year_t
    DROP TABLE year_t
    SET NOCOUNT OFF
    

    has worked for you???

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

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