Using CASE in the join statement in the AND clause. Where's the problem?

All,
I have my code, where based on the case statement, I would like to restrict the number of records in my JOIN condition. It's the CASE statement that I have used, that's giving me the problem. Not sure, what the problem is. The error says (in my case expression):
Msg 102, Level 15, State 1, Line 59
Incorrect syntax near '>'.
Select a.Col1, a.Col2, b.Col1, b.Col2, b.Col3
From Table1 a
Join Table2 b
On a.id = b.id
Join Table3 c
On c.FiltId = a.FiltId
And
Case
When b.Col3 <> 5 --b.Col3 is an INT field
Then (b.OutDate >= DATEADD(DAY, -30, c.InsertDate) And b.OutDate <= DATEADD(DAY, 30, c.InsertDate))
When b.Col3 = 5
Then (b.InDate >= DATEADD(DAY, 5, c.InsertDate))
End
Join Table 4 -- Other Join conditions and where clause conditions

You do not know the CASE is an expression and fields are not columns. This is fundamental and probably means that a lot of your code needs work. 
You can probably re-write the query with something like this: 
SELECT A.col1, A.col2, B.col1, B.col2, B.col3
  FROM Table_1 AS A, Table_2 AS B, Table_3 AS C
 WHERE A.generic_id = B.generic_id
   AND C.foobar_id = A.foobar_id
   AND CASE
       WHEN B.col3 <> 5 
            AND (B.something_out_date 
                 <= DATEADD(DAY, -30, C.something_insertion_date) 
       THEN 'T'
       WHEN B.col3 = 5 
            AND (B.something_out_date 
                >= DATEADD(DAY, -30, C.something_insertion_date) 
       THEN 'T'
       ELSE 'F' END = 'T' ;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • I am using my Description as the caption on Slideshow.  I ticked the "Show Title Slide" button and iPhoto physically copied the description on the first slide onto the end of every other description.  I can find no way of removing them other than by hand.

    I am using my Description as the caption on Slideshow.  I ticked the "Show Title Slide" button and iPhoto physically copied the description on the first slide onto the end of every other description.  I can find no way of removing them other than by hand.  Unticking the "show title slide" did not reverse the situation back to my required state.   Any ideas why it might have happened or how it might br resolved?   Regards, Marshfrog1

    Attached is Dennis Linam’s Audition – “Log File” and “Log – Last File”
    Contact information Dennis [email protected]
    Previous contact information with your organization (DURIM):
    Dennis - i just finished my audition trial and bought the subscription the 2014 version.
    created by durin in Audition CS5.5, CS6 & CC - View the full discussion 
    DURIM - Okay.  I would expect the "Cache Warning" message because your default directories would not be the same as the ones in the settings file I generated.
    If you go back to the "7.0" directory and open the "Logs" folder, can you copy the "Audition Log.txt" file and send it as an attachment to [email protected]?  We'll take a look in that logfile and see if it gives us more information about why this is failing now.
    Also, do you have any other Adobe applications installed on this machine, such as Premiere Pro?  If so, do they launch as expected or fail as well?
    I do have the trial Pro version of Adobe reader, but I have not activated it, because I fear the same thing will happen did it. I cannot afford to activate the subscription for that product and take the chance of it not working either. I depend on those two programs religiously. Here is the files that you requested. I appreciate any help you can give me to get this audition program started
    Audition Log- file
    Ticks = 16       C:\Program Files (x86)\Common Files\Adobe\dynamiclink\7.0\dynamiclinkmanager.exe
    Sent from Windows Mail

  • I am replacing my existing SATA hard drive to a Solid State hard drive and want to image the drive, is this possible?

    I am replacing my existing 320 GB SATA hard drive that clicks and makes weird noises to a Solid State hard drive and want to image the drive, is this possible?  I then want to replace the DVD with a secondary large drive for storage.
    So I am looking for any "gotchas" that I may be unaware of.
    Thanks!

    Put the Old drive in an external notebook drive enclosure. Install the SSD in your computer. Boot from your Old drive's Recovery HD:
    Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Clone Lion/Mountain Lion using Restore Option of Disk Utility
         1. Select Disk Utility from the main menu then press the Continue
             button.
         2. Select the destination volume from the left side list.
         3. Click on the Restore tab in the DU main window.
         4. Select the destination volume from the left side list and drag it
             to the Destination entry field.
         5. Select the source volume from the left side list and drag it to
             the Source entry field.
         6. Double-check you got it right, then click on the Restore button.
    Destination means the New SSD. Source means the external Old hard drive.
    Set the new Startup Disk to the SSD and restart the computer.
    This process clones both your old OS X volume and the Recovery HD volume to the SSD. You can use a similar process to clone the SSD to the new hard drive you will install.

  • Hello I am coming to the united stats next month and i have a broken iphone 4 What are my options ? And could i replace it with the new iphone 5 or other apple products ? And how much will it cost me .  Thank you for you're time.

    Hello
    I am coming to the united stats next month and i have a broken iphone 4
    What are my options ?
    And could i replace it with the new iphone 5 or other apple products ?
    And how much will it cost me .
    Thank you for you're time.
    <Edited by Host>

    If that iPhone was orignally sold in the US, Out of Warranty replacement cost
    will be
    Phone 4, iPhone 3GS,
    iPhone 3G, Original iPhone
    $149
    Replacement will be an iPhone of the same color and GB. There is no option to upgrade
    using Out of Warranty replacement.

  • I have just updated to iOS7, no icon for browser, was using Safari, how do I get it back and can I reverse the upgrade and go back to iOS6?

    I have just updated to iOS7, no icon for browser, was using Safari, how do I get it back and can I reverse the upgrade and go back to iOS6?  Thanks to you from the UnTechie

    The icon for Safari has probably moved to make room for new apps. Scroll the Home screen to look for it.
    You cannot reverse the upgrade.

  • Im having trouble connecting my macbookpro to the tv. im using a mini display port to hdmi adapter, when i switch tv/video to hdmi on the tv nothing pops up, and i dont have the arrangement tap on the display settings, please help!

    im having trouble connecting my macbookpro to the tv. im using a mini display port to hdmi adapter, when i switch tv/video to hdmi on the tv nothing pops up, and i dont have the arrangement tap on the display settings, please help!

    I've found that the order of operations, so-to-speak, can be important when hooking up mini display port to HDMI.  I have the most success with the following operations in this order:
    1)  Plug HDMI cable into mini displayport adapter (the cable should not be plugged into either the TV or the computer at this point)
    2)  Plug the mini displayport end of your new super-cable to the computer.
    3)  Plug the HDMI end into your TV.
    4)  Switch inputs on your TV to the proper input.
    5)  If still nothing on the TV, try a different HDMI port on your TV.
    Hopefully this helps!  Good luck.

  • HT3406 If I choose "restore from iTunes backup" to move everything from old phone.  Will I still be able to use the old phone for music and apps?  Can the old phone be docked up to the computer?  Or will the new and old phone overwrite each other in some

    If I choose "restore from iTunes backup" to move everything from old iphone to a new one, will I still be able to use the old phone for music and apps?  Can the old phone be docked up to that same computer every now and then?  Or will the new and old phone overwrite each other in some way?  In other words, are the two phones treated as different devices when the "restore" option is used to set up the new phone?   Thanks in advance.

    Yes, you can use the old iPhone as an iPod touch.
    Read this:
    http://support.apple.com/kb/HT3406

  • Hi, I'm using a Mac Pro here. I am trying to connect it with my NAS hard drive. But i could not connect to it because i have an ethernet which connects to the intranet in my company and Air Port for the internet.

    Hi, I'm using a Mac Pro here. I am trying to connect it with my NAS hard drive. But i could not connect to it because i have an ethernet which connects to the intranet in my company and Air Port for the internet and it could not detect the the ip address after i input the correct address on "Connect to Server" window. Please help! Urgent! Thanks

    I did not say it is not possible.
    I said if your company networks are monopolizing both ports, you should talk to them about what options are available.
    Maybe you can get the company Intranet over wireless if you change some configuration items such as Subnet Mask.
    Maybe you can get on the Internet over Ethernet.
    You really need to ask them, and do not let them blow you off because you have a Mac. If they balk, ask them how it would be done on a PC (becasue it will be the same on a Mac).

  • Is there any way to increase the font size in the Creative Cloud. Using a Lenovo Yoga 2 with 14" screen and care barely see the menus

    Is there any way to increase the font size in the Creative Cloud. Using a Lenovo Yoga 2 with 14" screen and care barely see the menus.

    In short, no. There is no fix yet. They only barely acknowledge there is a problem. The "fix" is to enable 200% UI scaling which makes everything comically huge and unusable. This is pretty much of a joke. A really, really EXPENSIVE joke.

  • I have changed by service provider and have a new number which i use on Iphone 5. The number shown on Facetime and Imessage is  still the old one. How do i update it

    I have changed by service provider and have a new number which i use on Iphone 5. The number shown on Facetime and Imessage is  still the old one. How do i update it

    Deregister your old phone from here if you regsitered it
    https://supportprofile.apple.com

  • Trying to use headphones to watch a show online...  sound still comes out of the internal speakers, not through my headphones.. i used help, said to go to sound preferences and choose headphones from the output pane, but it doesn't list headphones

    trying to use headphones to watch a show online...  sound still comes out of the internal speakers, not through my headphones.. i used help, said to go to sound preferences and choose headphones from the output pane, but it doesn't list headphones

    trying to do this on a macbook pro...please help

  • What is the Join condition between mtl_system_items_b and mtl_onhand_quantities_detail

    Hi,
    What is the Join condition between mtl_system_items_b and mtl_onhand_quantities_detail?
    Thanks & Regards,
    Hari Babu

    Please see the query in (Consolidate Onhand Quantity /Sum Quantity Zero in MTL_ONHAND_QUANTITIES_DETAIL (MOQD) / Concurrent Program Consolidate Inventory Onhand Quantities / Datafix for 0 Quantity Displayed For Finished Goods (Doc ID 353345.1)), is shows how to join those 2 tables.
    http://etrm.oracle.com
    Thanks,
    Hussein

  • What is the Join Between structures (sdpartnerlist) and (vbak or komv )

    Hi Dear ,
    can anyone tell me that  " what is the  Join Between structures (sdpartnerlist) and (vbak or komv ) "
    or how can i join these structures .

    Please do your own research before asking others.
    Thread locked.
    Thomas

  • HT1904 I purchased an iTunes card in the United States yesterday. I arrived home in the Bahamas today and tried to redeem the card  but got an error message stating that  I can only redeem  my card in a United States store. How to redeem a card outside th

    I purchased an iTunes card in the United States yesterday. I arrived home in the Bahamas today and tried to redeem the card but got an error message stating that  I can only redeem  the card in a United States store. How to redeem a card outside the US?

    Sorry - iTunes cards can only be redeemed in the country in which they were purchased.
    GB

  • I used to be able to copy or drag and drop links from the address window. Now with the update, only the address is copied or dragged not the link. (Says something about not giving site information). I want to be able to drag and drop or copy links.

    Question
    I used to be able to copy or drag and drop links from the address window. Now with the update, only the address is copied or dragged not the link. (Says something about not giving site information). I want to be able to drag and drop or copy links.

    To be more precise, you can setup a JComponent or JPanel on top of your JavaFX nodes that has a TransferHandler that can convert the (AWT/Swing) images dragged to the app to JavaFX image and then insert it into the underlying node.
    As for the file chooser itselft: ListView and the JavaFX composer can allow you to create one quite easily. TreeView can aslso be used to a lesser extend (still a big buggy). For both of these, there are small bugs in the Cell API that may (or may not) prevent from displaying a proper thumbnail in the cells.
    You can also use a regular JFileChooser if you do not mind the dialog box having a different LnF from the rest of your application.

  • I am thing of using Final Cut Pro but when I try and download I get the message "Your computer's video card does not meet the minimum system requirements." Can I do anything about this?

    I am thing of using Final Cut Pro but when I try and download I get the message “Your computer’s video card does not meet the minimum system requirements.” Can I do anything about this? I am using a Mac Pro early 2008 with Yosemite 10.10.2. My current graphics card is a ATI Radeon HD 2600 XT 256 MB.

    Geoff2T wrote:
    I am thing of using Final Cut Pro but when I try and download I get the message “Your computer’s video card does not meet the minimum system requirements.” Can I do anything about this? I am using a Mac Pro early 2008 with Yosemite 10.10.2. My current graphics card is a ATI Radeon HD 2600 XT 256 MB.
    It is just as the message says. Your video card is not compatible.
    You can add a compatible graphics card and use FCP X with your mac.  I can't suggest which one, but maybe other people on this forum can guide.
    And you may also get good suggestions in the Mac Pro forum.

Maybe you are looking for