Connecting Tech Pros Worldwide Help | Site Map

sql queries

  #1  
Old August 19th, 2008, 07:25 PM
mo/-/sin
Guest
 
Posts: n/a
hi.
i want to make a table in sql server 2005 and i want that there should
be two columns one if date and other for time......
i want that date column should show only date but not time and the
time column should show only time not date......
i tried this but when i enter only time it shows date also n that is
1900-01-01 and when i enter date it shows time also i.e 00:00:00...
  #2  
Old August 19th, 2008, 10:25 PM
Erland Sommarskog
Guest
 
Posts: n/a

re: sql queries


mo/-/sin (Ri.mohsin@gmail.com) writes:
Quote:
i want to make a table in sql server 2005 and i want that there should
be two columns one if date and other for time......
i want that date column should show only date but not time and the
time column should show only time not date......
i tried this but when i enter only time it shows date also n that is
1900-01-01 and when i enter date it shows time also i.e 00:00:00...
On SQL 2005 there are no date-only or time-only data types. However,
SQL 2008, just released have this.

In SQL 2005, the best you can do is:

datecol datetime CHECK (datecol = convert(char(8), datecol, 112)),
timecol datetime CHECK (convert(char(8), timecol, 112) = '19000101')

This constrains the time porttion for the date column to midnight, and
the date portion for the time column to 1900-01-01. The reason I picked
this date is that this is the "zero date" in SQL Server.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a batch of sql queries? mark.a.lemoine@gmail.com answers 7 March 2nd, 2006 08:05 PM
xslt queries in xml to SQL queries Ian Roddis answers 3 February 26th, 2006 07:05 PM
3 SQL queries in 1 string...in what order will they execute? rooster575 answers 2 November 18th, 2005 03:09 PM
How to handle sql queries Mikael Janers answers 4 November 15th, 2005 07:46 AM
Intercept SQL Queries sent to DB Vlade answers 1 July 20th, 2005 02:27 AM