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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Sql Query

Sql Query

Scheduled Pinned Locked Moved Database
databasehelp
2 Posts 2 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.
  • V Offline
    V Offline
    V 2
    wrote on last edited by
    #1

    I m facing a problem in this query select a.eventid,b.name,convert(nvarchar,c.assigndate,106)as assigndate, convert(nvarchar,a.eventdate,106)as eventdate,a.event,a.details,a.eventtype from event as a left outer join emp as c on a.eventid=c.eventid left outer join user_info as b on b.userid=c.userid where(a.eventtype='Single Month' or(a.eventtype='All Month' and (select substring(convert(nvarchar,edate,102),9,4) from event where eventtype='All Month')>( select substring(convert(nvarchar,getdate(),102),9,4)) ))order by a.eventdateselect * from event In event table there are some fields like eventid,eventdate,eventtype n etc In user_info there are userid, name n etc fields i wanna get all record when 1> eventtype is Single Month and the eventdate is in current month n eventdate is heigher than currentdate 2> eventype is All Month and eventdate is heigher than current date eventid -----eventdate ------- eventtype 1 -----2008-04-15 00:00:00 ----- All Month 2 -----2008-04-20 00:00:00 ----- Single Month 3 -----2008-04-16 00:00:00 ----- Single Month 4 -----2008-04-16 00:00:00 ----- All Month The answer shd be eventid 2,3,4

    The Great Pleasure In Doing That Things That Other People Say U Can't By Doing This U Can Shut Their Mouth

    A 1 Reply Last reply
    0
    • V V 2

      I m facing a problem in this query select a.eventid,b.name,convert(nvarchar,c.assigndate,106)as assigndate, convert(nvarchar,a.eventdate,106)as eventdate,a.event,a.details,a.eventtype from event as a left outer join emp as c on a.eventid=c.eventid left outer join user_info as b on b.userid=c.userid where(a.eventtype='Single Month' or(a.eventtype='All Month' and (select substring(convert(nvarchar,edate,102),9,4) from event where eventtype='All Month')>( select substring(convert(nvarchar,getdate(),102),9,4)) ))order by a.eventdateselect * from event In event table there are some fields like eventid,eventdate,eventtype n etc In user_info there are userid, name n etc fields i wanna get all record when 1> eventtype is Single Month and the eventdate is in current month n eventdate is heigher than currentdate 2> eventype is All Month and eventdate is heigher than current date eventid -----eventdate ------- eventtype 1 -----2008-04-15 00:00:00 ----- All Month 2 -----2008-04-20 00:00:00 ----- Single Month 3 -----2008-04-16 00:00:00 ----- Single Month 4 -----2008-04-16 00:00:00 ----- All Month The answer shd be eventid 2,3,4

      The Great Pleasure In Doing That Things That Other People Say U Can't By Doing This U Can Shut Their Mouth

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Try this select a.eventid,b.name,convert(nvarchar,c.assigndate,106)as assigndate, convert(nvarchar,a.eventdate,106)as eventdate,a.event,a.details,a.eventtype from event as a left outer join emp as c on a.eventid=c.eventid left outer join user_info as b on b.userid=c.userid WHERE a.eventdate > getdate() AND ( (a.eventtype = 'Single Month' and left(convert(varchar,getdate(),102),7) = left(convert(varchar,edate,102),7)) OR (a.eventtype = 'All Month') )

      Bob Ashfield Consultants Ltd

      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