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. joining two queries

joining two queries

Scheduled Pinned Locked Moved Database
helptutorialquestion
6 Posts 4 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.
  • C Offline
    C Offline
    csp
    wrote on last edited by
    #1

    select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Calls] from status join empmaster on empmaster.empid = status.empcode where empmaster.Permission <> '1' and logintime between '06/02/2006' and '06/03/2006' group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by empcode asc select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Contacts] from status join empmaster on empmaster.empid = status.employeecode where empmaster.Permission <> '1' and logintime between '06/02/2008' and '06/03/2008' and statuscode not in (11)group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by emp asc i have these two queries.the problem is how to join these queries? can any one help me.if i write two queries as one,data of two columns ( [no of calls] and [no of contacts]) resulting same count.

    B N 2 Replies Last reply
    0
    • C csp

      select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Calls] from status join empmaster on empmaster.empid = status.empcode where empmaster.Permission <> '1' and logintime between '06/02/2006' and '06/03/2006' group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by empcode asc select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Contacts] from status join empmaster on empmaster.empid = status.employeecode where empmaster.Permission <> '1' and logintime between '06/02/2008' and '06/03/2008' and statuscode not in (11)group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by emp asc i have these two queries.the problem is how to join these queries? can any one help me.if i write two queries as one,data of two columns ( [no of calls] and [no of contacts]) resulting same count.

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

      use UNION select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Calls] from status join empmaster on empmaster.empid = status.empcode where empmaster.Permission <> '1' and logintime between '06/02/2006' and '06/03/2006' group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by empcode asc **UNOIN** select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Contacts] from status join empmaster on empmaster.empid = status.employeecode where empmaster.Permission <> '1' and logintime between '06/02/2008' and '06/03/2008' and statuscode not in (11)group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by emp asc


      I Love T-SQL "Don't torture yourself,let the life to do it for you."

      A 1 Reply Last reply
      0
      • B Blue_Boy

        use UNION select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Calls] from status join empmaster on empmaster.empid = status.empcode where empmaster.Permission <> '1' and logintime between '06/02/2006' and '06/03/2006' group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by empcode asc **UNOIN** select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Contacts] from status join empmaster on empmaster.empid = status.employeecode where empmaster.Permission <> '1' and logintime between '06/02/2008' and '06/03/2008' and statuscode not in (11)group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by emp asc


        I Love T-SQL "Don't torture yourself,let the life to do it for you."

        A Offline
        A Offline
        A Wong
        wrote on last edited by
        #3

        Use "Union All" instead of "Union" if your 2 queries doesn't return duplicates.

        B 1 Reply Last reply
        0
        • A A Wong

          Use "Union All" instead of "Union" if your 2 queries doesn't return duplicates.

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

          Yes you are right, I forgot to write UNION ALL in both two places on my first response.Thanks for correcting me dude.


          I Love T-SQL "Don't torture yourself,let the life to do it for you."

          A 1 Reply Last reply
          0
          • B Blue_Boy

            Yes you are right, I forgot to write UNION ALL in both two places on my first response.Thanks for correcting me dude.


            I Love T-SQL "Don't torture yourself,let the life to do it for you."

            A Offline
            A Offline
            A Wong
            wrote on last edited by
            #5

            No problem. You beat me to the solution anyhow :laugh:

            1 Reply Last reply
            0
            • C csp

              select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Calls] from status join empmaster on empmaster.empid = status.empcode where empmaster.Permission <> '1' and logintime between '06/02/2006' and '06/03/2006' group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by empcode asc select convert(varchar(10),status.Logintime ,101) as Date,empcode,empname,count(*) as [No of Contacts] from status join empmaster on empmaster.empid = status.employeecode where empmaster.Permission <> '1' and logintime between '06/02/2008' and '06/03/2008' and statuscode not in (11)group by empcode,empname, convert(varchar(10),status.Logintime ,101) order by emp asc i have these two queries.the problem is how to join these queries? can any one help me.if i write two queries as one,data of two columns ( [no of calls] and [no of contacts]) resulting same count.

              N Offline
              N Offline
              Niraj_Silver
              wrote on last edited by
              #6

              if u wants to run both qries one after another then the Solution is.... SqlQry 1 Go Sqlqry 2 Go . . . . Try Go Statement in SQL it will help you... Enjoy your coding.. :-D

              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