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. Use if else statements to retrieve a certain column based on criteria and give it for display

Use if else statements to retrieve a certain column based on criteria and give it for display

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

    Hey Guys, Here is my issue - I have a table with 3 date fields. (Entry Date, Pending Date, Accounting Date) -> in my GridView I need to represent this value in 1 column called (Report Date). My rules are if Accounting Date is null use Finalized Date, if Pending date is null use Entry Date. This rule has to work on a row by row basis as I am returning 100's of rows. Now if this is better done in the code - I can do that also. Any help would greatly be appreciated. Thank you.

    P P 2 Replies Last reply
    0
    • N nit115

      Hey Guys, Here is my issue - I have a table with 3 date fields. (Entry Date, Pending Date, Accounting Date) -> in my GridView I need to represent this value in 1 column called (Report Date). My rules are if Accounting Date is null use Finalized Date, if Pending date is null use Entry Date. This rule has to work on a row by row basis as I am returning 100's of rows. Now if this is better done in the code - I can do that also. Any help would greatly be appreciated. Thank you.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Well, depending on whether or not your DBMS supports it, you could use the CASE statement to accomplish this, or you could use a COALESCE method,e.g.

      SELECT COALESCE(AccountingDate, PendingDate, EntryDate) AS RuleDate ...

      This assumes that one of these columns has a date value in it. Basically, coalesce falls through from one entry to the next until it finds a none-null value. BTW - I'm assuming that you got your logic a bit wrong in your statement and you mean Pending Date and not Finalized Date.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      My blog | My articles | MoXAML PowerToys

      1 Reply Last reply
      0
      • N nit115

        Hey Guys, Here is my issue - I have a table with 3 date fields. (Entry Date, Pending Date, Accounting Date) -> in my GridView I need to represent this value in 1 column called (Report Date). My rules are if Accounting Date is null use Finalized Date, if Pending date is null use Entry Date. This rule has to work on a row by row basis as I am returning 100's of rows. Now if this is better done in the code - I can do that also. Any help would greatly be appreciated. Thank you.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        CASE WHEN Accounting Date IS NULL THEN Finalized Date WHEN Pending date IS NULL THEN Entry Date END etc.

        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