Index on Date field

Results 1 to 2 of 2

Thread: Index on Date field

  1. #1
    Join Date
    Dec 1969

    Default Index on Date field

    I&#039;ve got a SQL server table with the following fields<BR><BR>JobID int<BR>JobDate datetime<BR>JobSt varchar(1)<BR><BR>I want to put a unique index on the fields above, each JobID can only have one JobSt on a JobDate , <BR>but because of the milliseconds in the date time it&#039;s not happening. Any ideas ?<BR><BR>Many thanks.<BR>Ron

  2. #2
    Join Date
    Dec 1969

    Default CONVERT(CHAR(8),JobDate,112)

    Index on CONVERT(CHAR(8),JobDate,112)<BR><BR>That will convert your datetime field to a string of the form "yyyymmdd" so it will even sort correctly, not to mention it will ignore the time. <BR><BR>Look here:<BR>

Posting Permissions

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