+ Reply to Thread
Page 3 of 3 FirstFirst 1 2 3
Results 21 to 25 of 25

Thread: CASE WHEN vs. BETWEEN

  1. #21
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Help me out -- are they showing NULL now in the result set? I've got about 3 different query problems working at the same time.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  2. #22
    Barn Frequenter BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche's Avatar
    Join Date
    Mar 2008
    Posts
    188
    Rep Power
    5

    They are showing as NULL, yes. A blank value on the page. NULL in the DB.
    "You'll never be as perfect as BLaaaaaaaaarche."

  3. #23
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    See the lines is bold below:
    Code:
      Select S.s_id, S.s_name, S.s_symbol, S.s_publisher, S.s_published_date
           , isNull(sum(Case when SD.sd_shares > 0 then SD.sd_shares else 0 end), 0) as sd_shares
           , isNull(AP.sd_price_per_share, 0) as sp_price_per_share
           , isNull(convert(varchar(10), MD.sd_date, 120), 'N/A') as sd_date
        From tblStocks S
        Left Join tblStocks_Detail SD
          On S.s_id = sd.s_id
        Left Join (
              Select s_id, max(sd_date) as sd_date
                From tblStocks_Detail
                Group by s_id
              ) as MD
          On (S.s_id = MD.s_id)
        Left Join (Select sd_id
                        , SUM(sd_shares * sd_price_per_share) / SUM(sd_shares) as sd_price_per_share
                     From tblStocks_Detail
                     Where sd_shares > 0
                     Group By sd_id
                    )  as AP
       Group By  S.s_id, S.s_name, S.s_symbol, S.s_publisher, S.s_published_date, AP.sp_price_per_share, MD.sd_date
    
    Note that the convert function will returns dates as YYYY-MM-DD (by using format code 120) to maintain sort order. You can use a different code if sort order is not important.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  4. #24
    Barn Frequenter BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche's Avatar
    Join Date
    Mar 2008
    Posts
    188
    Rep Power
    5

    Wolffy, that works perfect. I have certainly gained a lot of insight into SQL statements. Thanks again for all of your help.
    "You'll never be as perfect as BLaaaaaaaaarche."

  5. #25
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    No problem -- glad you got it sorted.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

+ Reply to Thread
Page 3 of 3 FirstFirst 1 2 3

Similar Threads

  1. switch case in c#
    By guddu in forum .NET Development
    Replies: 2
    Last Post: January 28th, 2009, 11:33 AM
  2. asp[classic] CASE equiv in php
    By Borojim in forum PHP Development
    Replies: 2
    Last Post: September 20th, 2008, 01:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO