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 Statment ProbLem

Sql Statment ProbLem

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.
  • S Offline
    S Offline
    soniasan
    wrote on last edited by
    #1

    Hi to all select ModelName from SRO_ModelMaster select RegionCode from cmp_RegionMaster SELECT Count(*) as 'TOT' FROM SRO_SurveySelectedModel,cmp_RegionMaster WHERE modelno in (Select ModelNo From SRO_ModelMaster where ModelName='FNRO') AND approved='Y' AND RosapCode in ( SELECT ROsapCode FROM SRO_ROMaster where region='ER') Please tell me how i can combine these three statments into Single SQL Statment I want to develop Stored procedure From this without using temp table Thanks & regard Sonia

    W 1 Reply Last reply
    0
    • S soniasan

      Hi to all select ModelName from SRO_ModelMaster select RegionCode from cmp_RegionMaster SELECT Count(*) as 'TOT' FROM SRO_SurveySelectedModel,cmp_RegionMaster WHERE modelno in (Select ModelNo From SRO_ModelMaster where ModelName='FNRO') AND approved='Y' AND RosapCode in ( SELECT ROsapCode FROM SRO_ROMaster where region='ER') Please tell me how i can combine these three statments into Single SQL Statment I want to develop Stored procedure From this without using temp table Thanks & regard Sonia

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Basically you need to join those tables and then group by ModelName and RegionCode but to get this statement further: what is the relationship between those four tables? Your query should look something like:

      SELECT SRO_ModelMaster.ModelName,
      cmp_RegionMaster.RegionCode,
      Count(*) as 'TOT'
      FROM SRO_SurveySelectedModel,
      cmp_RegionMaster,
      SRO_ModelMaster,
      SRO_ROMaster
      WHERE ???.modelno = SRO_ModelMaster.ModelNo
      AND SRO_ModelMaster.ModelName='FNRO'
      AND ???.approved='Y'
      AND ???.RosapCode = SRO_ROMaster.ROsapCode
      AND SRO_ROMaster.region='ER'
      AND SRO_ROMaster.??? = ???.???
      GROUP BY SRO_ModelMaster.ModelName,
      cmp_RegionMaster.RegionCode

      The need to optimize rises from a bad design. My articles[^]

      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