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. General Programming
  3. C#
  4. SQL SCRIPT

SQL SCRIPT

Scheduled Pinned Locked Moved C#
databasetoolshelpquestion
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.
  • K Offline
    K Offline
    kibromg
    wrote on last edited by
    #1

    Hi Guys, I am having problem when running the Following SQL script.It takes Pretty long time to return result. I am having about 500,000 records in my database. select count(distinct(CR_Cli)),SO_name from Callrecords inner join dbo.StudioOperators On CR_StudioOperatorID=SO_ID where datename(month,cr_callstart)='April' and Cr_cli not in (select Cr_cli from Callrecords where cr_callstart<'2009-03-31') group by SO_name desc Is there any way i can write this script? Thanks you very much.

    H P 2 Replies Last reply
    0
    • K kibromg

      Hi Guys, I am having problem when running the Following SQL script.It takes Pretty long time to return result. I am having about 500,000 records in my database. select count(distinct(CR_Cli)),SO_name from Callrecords inner join dbo.StudioOperators On CR_StudioOperatorID=SO_ID where datename(month,cr_callstart)='April' and Cr_cli not in (select Cr_cli from Callrecords where cr_callstart<'2009-03-31') group by SO_name desc Is there any way i can write this script? Thanks you very much.

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      You do realise that there are several Database related fora on CP? This is a C# forum.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      K 1 Reply Last reply
      0
      • H Henry Minute

        You do realise that there are several Database related fora on CP? This is a C# forum.

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        K Offline
        K Offline
        kibromg
        wrote on last edited by
        #3

        Sorry I couldnt get SQL forum From the Message Board List. I will Try MYSQL. Thank you

        D H 2 Replies Last reply
        0
        • K kibromg

          Sorry I couldnt get SQL forum From the Message Board List. I will Try MYSQL. Thank you

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          How about the "General Database" forum??

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          1 Reply Last reply
          0
          • K kibromg

            Sorry I couldnt get SQL forum From the Message Board List. I will Try MYSQL. Thank you

            H Offline
            H Offline
            Henry Minute
            wrote on last edited by
            #5

            General Database might be better, if it is MS SQLServer.

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            1 Reply Last reply
            0
            • K kibromg

              Hi Guys, I am having problem when running the Following SQL script.It takes Pretty long time to return result. I am having about 500,000 records in my database. select count(distinct(CR_Cli)),SO_name from Callrecords inner join dbo.StudioOperators On CR_StudioOperatorID=SO_ID where datename(month,cr_callstart)='April' and Cr_cli not in (select Cr_cli from Callrecords where cr_callstart<'2009-03-31') group by SO_name desc Is there any way i can write this script? Thanks you very much.

              P Offline
              P Offline
              PauloCastilho
              wrote on last edited by
              #6

              It´s very hard to rewrite a SQL query that I didn´t know the schema and relationships. Anyway, I made some changes.

              kibromg wrote:

              select count(distinct(CR_Cli))

              Verify if the column has an index.

              kibromg wrote:

              datename(month,cr_callstart)='April'

              Do not use much functions on where clause. Simplify... use "month(CR.callstart) = 4".

              kibromg wrote:

              and Cr_cli not in (select Cr_cli from Callrecords where cr_callstart<'2009-03-31')

              If Cr_Cli "not in" where cr_callstart < '2009-03-31 then Cr_Cli "is in" where cr_callstart > '2009-03-30'. More than that, you are already referencing Callrecords in inner join, so you don´t need to create a subselect. On where clause, use this condition: "CR.callstart > '2009-03-30'".

              kibromg wrote:

              group by SO_name desc

              On group by you have the column SO_name. Does this column have an index?! If not, you must consider creating one. Try the code below, maybe it helps. select count(distinct(CR.Cli)) , SO.name from Callrecords CR inner join StudioOperators SO on CR.StudioOperatorID = SO.ID where month(CR.callstart) = 4 and CR.callstart > '2009-03-30' group by SO.name desc

              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