intersection data in MS SQL 2000 server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zybernau
    New Member
    • Mar 2007
    • 34

    #1

    intersection data in MS SQL 2000 server

    Hi All,

    i am using Sql Server 2000,
    i am having table table1 which have columns field1 , date1
    which can have data like this [sample]

    field1 date1
    12 2007-12-25
    12 2007-12-26
    12 2007-12-27
    12 2007-12-28
    13 2007-12-25
    13 2008-01-25
    14 2007-12-25
    14 2008-01-15
    15 2008-01-15
    15 2008-01-15
    15 2008-01-15

    i will be having data across years for the same field1
    i need to take only those records which have records on the both year [2008 and 2007]

    i tried using intersect , but its not working in sql server 2000

    Thanks
    -Raj
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by zybernau
    Hi All,

    i am using Sql Server 2000,
    i am having table table1 which have columns field1 , date1
    which can have data like this [sample]

    field1 date1
    12 2007-12-25
    12 2007-12-26
    12 2007-12-27
    12 2007-12-28
    13 2007-12-25
    13 2008-01-25
    14 2007-12-25
    14 2008-01-15
    15 2008-01-15
    15 2008-01-15
    15 2008-01-15

    i will be having data across years for the same field1
    i need to take only those records which have records on the both year [2008 and 2007]

    i tried using intersect , but its not working in sql server 2000

    Thanks
    -Raj

    try:

    select * from yourtable where datepart(year, date1) between 2008 and 2007

    or


    select * from yourtable where datepart(year, date1) in (2008, 2007)


    happy coding...


    --- CK

    Comment

    Working...