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. joins of two tables +search

joins of two tables +search

Scheduled Pinned Locked Moved Database
help
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.
  • R Offline
    R Offline
    regin
    wrote on last edited by
    #1

    hi... plz somone help me write these queries.. i want to search the data's from employee select the employee name,designation_name where 1)employee code that i can pass or else designation name i can pass 2)only one i can pass from theses 2 3)the employee can contain null value for desination name 4)constraint is :employee.designation_id=desig.designation_id plz somone help me out to solve this pblm

    P A 2 Replies Last reply
    0
    • R regin

      hi... plz somone help me write these queries.. i want to search the data's from employee select the employee name,designation_name where 1)employee code that i can pass or else designation name i can pass 2)only one i can pass from theses 2 3)the employee can contain null value for desination name 4)constraint is :employee.designation_id=desig.designation_id plz somone help me out to solve this pblm

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      What part of your code are you specifically having difficulties with? At the moment, it sounds like you want someone to do your work for you. You haven't stated what database you are you using. However if it is SQL Server, I suggest you do some research on writing stored procedures to encapsulate the logic for your search.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      1 Reply Last reply
      0
      • R regin

        hi... plz somone help me write these queries.. i want to search the data's from employee select the employee name,designation_name where 1)employee code that i can pass or else designation name i can pass 2)only one i can pass from theses 2 3)the employee can contain null value for desination name 4)constraint is :employee.designation_id=desig.designation_id plz somone help me out to solve this pblm

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

        For SQL-Server:

        select employee.name, designation.name
        from employee
        left outer join designation
          on designation.designation_id = employee.designation_id
        where employee.code = IsNull(@EmployeeCode, employee.code)
        and IsNull(designation.name, '') = IsNull(@DesignationName, designation.name)
        order by employee.name
        

        The outer join links the two tables together - even if there is no designation. The IsNull bit allows you to optionally pass in a NULL or a proper value for the employee code and the designation. Hope that helps. Andy

        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