Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Query

Query

Scheduled Pinned Locked Moved Database
databasehelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sarang_k
    wrote on last edited by
    #1

    Hi all, I created a table in which there r n fields and in that two of them are date field i.e., startdate and enddate. Now i want to write a query,to fetch the records from table which comes under startdate and enddate. so,i need a help how to write the query. Thanks in advance.

    B N 2 Replies Last reply
    0
    • S sarang_k

      Hi all, I created a table in which there r n fields and in that two of them are date field i.e., startdate and enddate. Now i want to write a query,to fetch the records from table which comes under startdate and enddate. so,i need a help how to write the query. Thanks in advance.

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      What you did so far? Have you try to write a query? As I could understood you then query should be like: select startdate,enddate from mytable where startdate >'2009.12.01' and enddate > '2009.12.22'


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      1 Reply Last reply
      0
      • S sarang_k

        Hi all, I created a table in which there r n fields and in that two of them are date field i.e., startdate and enddate. Now i want to write a query,to fetch the records from table which comes under startdate and enddate. so,i need a help how to write the query. Thanks in advance.

        N Offline
        N Offline
        Niladri_Biswas
        wrote on last edited by
        #3

        Try this

        declare @t table(somevalue varchar(100),startdate datetime, enddate datetime)
        insert into @t
        select 'somevalue1','01/14/2009', '01/20/2009' union all
        select 'somevalue2','01/15/2009', '01/22/2009' union all
        select 'somevalue3','01/18/2009', '01/31/2009' union all
        select 'somevalue4','02/01/2009', '02/10/2009' union all
        select 'somevalue5','05/14/2009', '05/20/2009'

        I want to get the records where between '01/14/2009' and '02/01/2009' (inclusive) Query:

        select * from @t
        where startdate >='01/14/2009' and enddate <='02/01/2009'

        Output: somevalue startdate enddate

        somevalue1 2009-01-14 00:00:00.000 2009-01-20 00:00:00.000
        somevalue2 2009-01-15 00:00:00.000 2009-01-22 00:00:00.000
        somevalue3 2009-01-18 00:00:00.000 2009-01-31 00:00:00.000

        :)

        Niladri Biswas

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups