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. what is the use of case statement

what is the use of case statement

Scheduled Pinned Locked Moved Database
question
4 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.
  • C Offline
    C Offline
    Chandrakanta Sen
    wrote on last edited by
    #1

    I have a table named as depot_mstr having attributes, are the following--- regn, depot_code, depot_name, city I have also an another table as dealer_list having attributes, are the following--- depot_no, depot_code, dealer_name, dealer_category how i get the output as--- regn| depot_code| dealer_name| GC| SC| STA| OTH where, GC, SC, STA, OTH are the elements of dealer_category

    P 1 Reply Last reply
    0
    • C Chandrakanta Sen

      I have a table named as depot_mstr having attributes, are the following--- regn, depot_code, depot_name, city I have also an another table as dealer_list having attributes, are the following--- depot_no, depot_code, dealer_name, dealer_category how i get the output as--- regn| depot_code| dealer_name| GC| SC| STA| OTH where, GC, SC, STA, OTH are the elements of dealer_category

      P Offline
      P Offline
      Peter Leow
      wrote on last edited by
      #2

      Assuming you are using sql server:

      SELECT regn, depot_code, dealer_name, GC, SC, STA, OTH
      FROM
      (SELECT regn, depot_mstr.depot_code, dealer_name, dealer_category FROM depot_mstr LEFT
      JOIN dealer_list ON depot_mstr.depot_code = dealer_list.depot_code
      ) AS sourcetable
      PIVOT
      (
      COUNT (dealer_category)
      FOR dealer_category IN
      (GC, SC, STA, OTH)
      ) AS pivottable

      C J 2 Replies Last reply
      0
      • P Peter Leow

        Assuming you are using sql server:

        SELECT regn, depot_code, dealer_name, GC, SC, STA, OTH
        FROM
        (SELECT regn, depot_mstr.depot_code, dealer_name, dealer_category FROM depot_mstr LEFT
        JOIN dealer_list ON depot_mstr.depot_code = dealer_list.depot_code
        ) AS sourcetable
        PIVOT
        (
        COUNT (dealer_category)
        FOR dealer_category IN
        (GC, SC, STA, OTH)
        ) AS pivottable

        C Offline
        C Offline
        Chandrakanta Sen
        wrote on last edited by
        #3

        Please also send me the code as early as possible, if i solve it through function in sql server... Thank u...

        1 Reply Last reply
        0
        • P Peter Leow

          Assuming you are using sql server:

          SELECT regn, depot_code, dealer_name, GC, SC, STA, OTH
          FROM
          (SELECT regn, depot_mstr.depot_code, dealer_name, dealer_category FROM depot_mstr LEFT
          JOIN dealer_list ON depot_mstr.depot_code = dealer_list.depot_code
          ) AS sourcetable
          PIVOT
          (
          COUNT (dealer_category)
          FOR dealer_category IN
          (GC, SC, STA, OTH)
          ) AS pivottable

          J Offline
          J Offline
          Jubayer Ahmed
          wrote on last edited by
          #4

          I can't find any case using in the query....!!!

          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