SQL Server Performance

how to cast this column

Discussion in 'SQL Server 2005 General Developer Questions' started by avipenina, Dec 28, 2007.

  1. avipenina New Member

    H,
    how do i cast this column
    "select create_date from sys.databases" to only show date, for example 2003-05-20.
    Thx
  2. Adriaan New Member

    In a query, use the CONVERT() function with the appropriate formatting option - see Books Online.
    Other than that, there is no way to suppress the time part - unless you move to SQL 2008, which has a true data type for dates.
  3. avipenina New Member

    can u show me how to convert the create_date from sys.databases into example (28.06.07) format?
    Thx
  4. Adriaan New Member

    Not sure about SQL 2005 - is this a Julian date? You probably need to do a calculation before applying the CONVERT function.
    Check out Frank Kalis's extensive article on date handling, available from the main page of the SSP site.
  5. avipenina New Member

    ok so help with this one.
    how do i take only the "names" that not in those 2 columns
    select distinct database_name from dbo.backupset AND select name from sys.databases
    i need only the names that are not in those 2 tables.
    Thx
  6. Madhivanan Moderator

    [quote user="avipenina"]
    ok so help with this one.
    how do i take only the "names" that not in those 2 columns
    select distinct database_name from dbo.backupset AND select name from sys.databases
    i need only the names that are not in those 2 tables.
    Thx
    [/quote]If not exists
    (select database_name from dbo.backupset where database_name=@yourdb
    union all
    select name from sys.databases where name=@yourdb)--do stuff
  7. Madhivanan Moderator

    [quote user="Adriaan"]
    Not sure about SQL 2005 - is this a Julian date? You probably need to do a calculation before applying the CONVERT function.
    Check out Frank Kalis's extensive article on date handling, available from the main page of the SSP site.
    [/quote]
    Created_date in sys.databases is of DATETIME datatype [:)]
  8. satya Moderator

Share This Page