Problem with case when statement, when doing an insert.

Hi there,  I have written the following coding, that has got an issue, due to not being allowed null values to be inserted into a column on a table.
,Case 
WHENCL.LocationISNOTNULLANDCL.[Floor]ISNOTNULLANDCL.RoomISNULLTHEN
(SELECTTop1
FL.FloorIDFROMPMIS.dbo.ConsentLocationF
JOINtbBuildingBONB.BuildingNumber=F.LocationCOLLATELatin1_General_CI_AS
JOINtbFloorFLONFL.BuildingID=B.BuildingID
WHEREF.Location=CL.LocationANDFL.FloorName=CL.[Floor]COLLATELatin1_General_CI_AS)
WHENCL.LocationISNOTNULLANDCL.[Floor]ISNOTNULLANDCL.RoomISNOTNULLTHEN
(SELECTTop1
R.RoomIDFROMPMIS.dbo.ConsentLocationF
JOINtbBuildingBONB.BuildingNumber=F.LocationCOLLATELatin1_General_CI_AS
JOINtbFloorFLONFL.BuildingID=B.BuildingID
JOINtbRoomRONR.FloorID=FL.FloorID
WHEREF.Location=CL.LocationANDFL.FloorName=CL.[Floor]COLLATELatin1_General_CI_ASANDR.RoomNumber=CL.RoomCOLLATELatin1_General_CI_AS)
ENDasParentID
I have written this case when statement above to find a ParentID.  I have got the case when statement to work individually, e.g. I get the correct records back.  However when I put it into a insert statement, as I want this ParentID to go
into a column in a table I get an error with the following message. 
Cannot insert the value NULL into column 'ParentID', table 'K2_Master_4_Test.dbo.tbConsentLink'; column does not allow nulls. INSERT fails.
Can someone point me in the right direction, as to what I need to do to get this case when statement working?  Also no I cannot change the structure of the table to allow for null values either.  So I need to modifiy this one.

The error is valid because your table column has 'not null' constraint and when your case expression does not satisfy  either of the 'when' conditions, it is returning NULL to the insert statement.
you can get around this by defining a generic value. Simple Example
select case when <<Column>>=1 then 'First' When <<Column>>=2 then 'Second' Else 'Last' End
In this case, when column value is not 1 or 2, it will insert 'Last'.
So, you have to do something like this...i.e add ELSE condition to your case..
Hope it Helps!!

Similar Messages

  • When attempting to use Lightroom external editor program to edit a photo in Photoshop Elements 10, the photo does not open / appear on photoshop elements screen.  I don't have any problem with this when using Photoshop Elements 6 or Photoshop CS.  I'm usi

    When attempting to use Lightroom external editor program to edit a photo in Photoshop Elements 10, the photo does not open / appear on photoshop elements screen.  I don't have any problem with this when using Photoshop Elements 6 or Photoshop CS.  I'm using a Mac with Mountain Lion OS.  Any solutions?

    Adobe now hides the editor - what looks like it is not - you want the editor hidden in the support folder - see http://forums.adobe.com/message/3955558#3955558 for details
    LN

  • I refurbished my macbook air 7 months ago because there was a problem with the steady state drive. Now my battery seems to be dead again. How long does the warranty last? Do I need to pay for a new battery?

    I refurbished my macbook air 7 months ago because there was a problem with the steady state drive. Now my battery seems to be dead again. How long does the warranty last? Do I need to pay for a new battery?

    As I wrote Apple will diagnose an Apple product even if it is out of warranty for free. That should be your first step to find out if the problem is the battery or something else.
    Once you have Apple telling you a 7 month old battery is defective (if that turns out to be the case)  then it becomes a game of horse trading. You'll need to speak to the tech and when he tells you there is nothing he can do you will need to speak to the tech manager and when she says most likely there is nothing they can do you go to the store manager, etc.  It is unlikely (though possible) that they will give in easily you need to be firm, polite and let on that you're willing to accept a partial reimbursement.
    So again the first step is to find out what is wrong.
    good luck

  • Problem with SDO_relate when using polygons with holes.

    I'm having a problem with sdo_relate. I'm trying to extract all elements from a point table (bdtq_batim_p) that are inside a specific polygon from another table (SDA_MUNIC_SS). The spatial index for both table have been rebuilt and the data from both table is valid.
    When I do a count on the query, I know the answer should be 1422 elements (Counted in ArcGIS). However, sdo_relate gives a smaller number of elements in the result set.
    The query :
    SELECT count(distinct t.identifiant) FROM bdtq_batim_p t, SDA_MUNIC_SS s WHERE s.mus_co_geo = '48015' and sdo_relate( t.SHAPE,s.SHAPE,'mask=anyinteract querytype=window') = 'TRUE'
    returns 282 elements. The query with mask=inside, SDO_Anyinteract() and SDO_inside() all give the same result.
    I did a test with the following query and the result is 1422 (which is the good result).
    SELECT count(distinct t.identifiant) FROM bdtq_batim_p t, SDA_MUNIC_SS s WHERE s.mus_co_geo = '48015' and SDO_WITHIN_DISTANCE( t.SHAPE,s.SHAPE,'distance=0') = 'TRUE';
    It's important to note that the polygone (from SDA_MUNIC_SS) that is used for this query have holes in it. I have the same problem with all the polygons from the SDA_MUNIC_SS table that have holes in it. For the polygon without holes, the results are the same for the 2 queries.
    My question are :
    Why are the result from the two queries different? A query with a buffer of 0 should always return the same result as a query with Anyinteract.
    Is there a known problem with SDO_RELATE when using a polygon with holes in it?
    Do you have any idea how to solve my problem.

    Since i don't have much control on the version of Oracle and Patches that we use in the system, we used a workaround that detects the polygons with holes and uses the SDO_WITHIN_DISTANCE( t.SHAPE,s.SHAPE,'distance=0') = 'TRUE' operator in those case. We saw a slight decline in performance but it now returns the right results. When the system will be patched, we'll come back to the original version and see if the problem is solved.

  • Strange problem with SQLPLUS when client and server on the same box

    Hi,
    I have the problem with SQLPLUS when clinet and server on the same machine.
    With client and server on the same machine i am running the command
    sqlplus -l username/password@connect_identifier as SYSDBA.
    With this command, even if you pass in wrong username or wrong password or both as wrong you can able to connect to database and execute queries.
    Once Connect_identifier is correct and trying to log in as SYSDBA ,sqlplus will log in to DB with any username and password.
    How to get rid of this behaviour. Is there any way to do this.
    I am running this command by creating a process in C#
    Edited by: user11000236 on Jun 16, 2009 10:31 AM

    user11000236 wrote:
    Thanks for the info.
    How does Oracle/SQLPLUS allows any username or password to log in to DB with SYSDBA Privillages? What is the concept behind this.?
    This is explainted in the above mentioned link:
    Operating system authentication takes precedence over password file authentication. If you meet the requirements for operating system authentication, then even if you use a password file, you will be authenticated by operating system authentication.

  • CS 4 Dynamic Link to Encore doesn't work most of the time.  Encore stops operating after opening and periodically Premier Pro stops working.  I'm told that there has been a problem with CS4 when using Dynamic Link to go to Encore and build CD's.  Is there

    CS 4 Dynamic Link to Encore doesn't work most of the time.  Encore stops operating after opening and periodically Premier Pro stops working.  I'm told that there has been a problem with CS4 when using Dynamic Link to go to Encore and build CD's.  Is there a way around this?  Is there a patch to correct it?

    To build CD's???
    What problem does Encore have with DL?
    If DL is not working properly for you the way around this is to export from Premiere to either mpeg2-dvd for DVD or BluRay H.264 for BD-disks and import the files in Encore.

  • Boundary on "CASE WHEN" does not what i expect

    Hi!
    The results of query1 are exactly what i expect but when i compare the counts with CASE WHEN (query2) then i get double records where the count is exactly 8. The value of Result on the second record becomes Null. This seems to me somewhat strange.
    Any suggestion?
    query1:
    SELECT DISTINCT inline_view.u_plot_number AS Research_Group,
           inline_view.external_reference AS Parental_Line,
           inline_view.u_box_code AS Box,
           inline_view.description AS Test,
           COUNT(NVL(inline_view_finalresult.u_overruled_result,inline_view_finalresult.u_calculated_result))
              OVER (PARTITION BY CONCAT(inline_view_finalresult.u_sdg_id,inline_view_finalresult.u_test_template_id)) AS R1,
           COUNT(DISTINCT NVL(inline_view_finalresult.u_overruled_result,inline_view_finalresult.u_calculated_result))
              OVER (PARTITION BY CONCAT(inline_view_finalresult.u_sdg_id,inline_view_finalresult.u_test_template_id)) AS R2
    FROM ( SELECT DISTINCT sdg.sdg_id,
                  sample.sample_id,
                  test_template.test_template_id,
                  sample_user.u_plot_number,
                  sdg.external_reference,
                  sample_user.u_box_code,
                  test.description
           FROM sdg,sdg_user,sample,sample_user,aliquot,test,test_template
           WHERE sdg.sdg_id = sdg_user.sdg_id
              AND sdg.sdg_id = sample.sdg_id
              AND sample.sample_id = sample_user.sample_id
              AND aliquot.sample_id = sample.sample_id
              AND test.aliquot_id = aliquot.aliquot_id
              AND test_template.test_template_id = test.test_template_id
              AND sdg.sdg_id >505
         ) inline_view,
         ( SELECT DISTINCT u_finalresult_user.u_sdg_id,
                  u_finalresult_user.u_calculated_result,
                  u_finalresult_user.u_overruled_result,
                  u_finalresult_user.u_sample_id,
                  u_finalresult_user.u_test_template_id
           FROM u_finalresult_user
           WHERE u_finalresult_user.u_requested = 'T'
         ) inline_view_finalresult
    WHERE inline_view.sample_id = inline_view_finalresult.u_sample_id (+)
       AND inline_view.test_template_id = inline_view_finalresult.u_test_template_id (+)
    ORDER BY inline_view.description,inline_view.u_box_codequery2:
    SELECT DISTINCT inline_view.u_plot_number AS Research_Group,
           inline_view.external_reference AS Parental_Line,
           inline_view.u_box_code AS Box,
           inline_view.description AS Test,
           CASE WHEN
                COUNT(NVL(inline_view_finalresult.u_overruled_result,inline_view_finalresult.u_calculated_result))
                OVER (PARTITION BY CONCAT(inline_view_finalresult.u_sdg_id,inline_view_finalresult.u_test_template_id)) < 8
             THEN
                'onv'
             ELSE
                CASE WHEN
                       COUNT(DISTINCT(NVL(inline_view_finalresult.u_overruled_result,inline_view_finalresult.u_calculated_result)))
                       OVER (PARTITION BY CONCAT(inline_view_finalresult.u_sdg_id,inline_view_finalresult.u_test_template_id)) > 1
                     THEN
                       'spl'
                     ELSE
                      NVL(inline_view_finalresult.u_overruled_result,inline_view_finalresult.u_calculated_result)
                END
          END AS Result
    FROM ( SELECT DISTINCT sdg.sdg_id,
                  sample.sample_id,
                  test_template.test_template_id,
                  sample_user.u_plot_number,
                  sdg.external_reference,
                  sample_user.u_box_code,
                  test.description
           FROM sdg,sdg_user,sample,sample_user,aliquot,test,test_template
           WHERE sdg.sdg_id = sdg_user.sdg_id
              AND sdg.sdg_id = sample.sdg_id
              AND sample.sample_id = sample_user.sample_id
              AND aliquot.sample_id = sample.sample_id
              AND test.aliquot_id = aliquot.aliquot_id
              AND test_template.test_template_id = test.test_template_id
              AND sdg.sdg_id >505
         ) inline_view,
         ( SELECT DISTINCT u_finalresult_user.u_sdg_id,
                  u_finalresult_user.u_calculated_result,
                  u_finalresult_user.u_overruled_result,
                  u_finalresult_user.u_sample_id,
                  u_finalresult_user.u_test_template_id
           FROM u_finalresult_user
           WHERE u_finalresult_user.u_requested = 'T'
         ) inline_view_finalresult
    WHERE inline_view.sample_id = inline_view_finalresult.u_sample_id (+)
       AND inline_view.test_template_id = inline_view_finalresult.u_test_template_id (+)
    ORDER BY inline_view.description,inline_view.u_box_code

    NVL(inline_view_finalresult.u_overruled_result,inline_view_finalresult.u_calculated_result)does not return double records without the CASE WHEN (see below) but i don't understand why it comes that when i compares the counts in a CASE WHEN that i get double records where the second record has value Null as Result. Could somebody provide me with a solution?
    SELECT DISTINCT inline_view.u_plot_number AS Research_Group,
           inline_view.external_reference AS Parental_Line,
           inline_view.u_box_code AS Box,
           inline_view.description AS Test,
           COUNT(NVL(inline_view_finalresult.u_overruled_result,inline_view_finalresult.u_calculated_result))
              OVER (PARTITION BY CONCAT(inline_view_finalresult.u_sdg_id,inline_view_finalresult.u_test_template_id)) AS R1,
           COUNT(DISTINCT NVL(inline_view_finalresult.u_overruled_result,inline_view_finalresult.u_calculated_result))
              OVER (PARTITION BY CONCAT(inline_view_finalresult.u_sdg_id,inline_view_finalresult.u_test_template_id)) AS R2,
    NVL(inline_view_finalresult.u_overruled_result,inline_view_finalresult.u_calculated_result) AS Result
    FROM ( SELECT DISTINCT sdg.sdg_id,
                  sample.sample_id,
                  test_template.test_template_id,
                  sample_user.u_plot_number,
                  sdg.external_reference,
                  sample_user.u_box_code,
                  test.description
           FROM sdg,sdg_user,sample,sample_user,aliquot,test,test_template
           WHERE sdg.sdg_id = sdg_user.sdg_id
              AND sdg.sdg_id = sample.sdg_id
              AND sample.sample_id = sample_user.sample_id
              AND aliquot.sample_id = sample.sample_id
              AND test.aliquot_id = aliquot.aliquot_id
              AND test_template.test_template_id = test.test_template_id
              AND sdg.sdg_id >505
         ) inline_view,
         ( SELECT DISTINCT u_finalresult_user.u_sdg_id,
                  u_finalresult_user.u_calculated_result,
                  u_finalresult_user.u_overruled_result,
                  u_finalresult_user.u_sample_id,
                  u_finalresult_user.u_test_template_id
           FROM u_finalresult_user
           WHERE u_finalresult_user.u_requested = 'T'
         ) inline_view_finalresult
    WHERE inline_view.sample_id = inline_view_finalresult.u_sample_id (+)
       AND inline_view.test_template_id = inline_view_finalresult.u_test_template_id (+)
    ORDER BY inline_view.description,inline_view.u_box_code

  • Having a problem with dates when I send my numbers doc to excel. dates are all out and that they have to cut and paste individual entries onto their spreadsheet. Any idea how I can prevent this

    having a problem with dates when I send my numbers doc to excel. dates are all out and that they have to cut and paste individual entries onto their spreadsheet. Any idea how I can prevent this.
    I'm using Lion on an MBP and Numbers is the latest version

    May you give more details about what is wrong with your dates ?
    M…oSoft products aren't allowed on my machines but I use LibreOffice which is a clone of Office.
    When I export from Numbers to Excel and open the result with LibreOffice, the dates are correctly treated.
    To be precise, dates after 01/01/1904 are correctly treated. dates before 01/01/1904 are exported as strings but, as it's flagged during the export process, it's not surprising.
    Yvan KOENIG (VALLAURIS, France) mardi 3 janvier 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : http://public.me.com/koenigyvan
    Please : Search for questions similar to your own before submitting them to the community
    For iWork's applications dedicated to iOS, go to :
    https://discussions.apple.com/community/app_store/iwork_for_ios

  • I have a problem with itunes when I sync the saved music and want to sync my iphone 5 ios 7.0.6 no longer passes the music thing is that just stays on "waiting for sync" and not worry please help are more than 400 songs that do not want to hear who are wi

    I have a problem with itunes when I sync the saved music and want to sync my iphone 5 ios 7.0.6 no longer passes the music thing is that just stays on "waiting for sync" and not worry please help are more than 400 songs that do not want to hear who are wi

    Plawexki wrote:
    ...  do you know if the contacts, photos, messages etc will be wiped?
    Yes... Everything will be Wiped and Replaced with what is currently on Your Mac.
    SYNCING with iTunes
    See here  >  http://support.apple.com/kb/HT1386
    From Here  >  http://www.apple.com/support/iphone/syncing/
    You may find this information of interest...
    Have a read here...
    https://discussions.apple.com/message/18409815?ac_cid=ha
    And See Here...
    How to Use Multiple iDevices with One Computer

  • Problems with navigation when deploy application on WebLogic 10.3

    Hi! I have problems with navigation when I deploy my application on Weblogic server 10.3. In my application I have two pages. One page where I can see the records. In this page I have button Create with action to secound jspx page. When I press this button then the first form (where I could see all records) is empty - the create operation worked, but navigation to second page not. Navigation rules is in adf task flow. In default server all works correct. Where is the problem?
    Maybe when I deploy my application I need specialy deploy adf task flow or somewhere write something? If so, then can you explain me where? Any suggestions what to do.
    Best regards!

    I have in log:
    2009.26.3 20:12:52 oracle.adfinternal.controller.faces.lifecycle.JSFLifecycleImp
    l setLifecycleContextBuilder
    WARNING: ADFc: Replacing the ADF Page Lifecycle implementation with 'oracle.adfi
    nternal.controller.application.model.JSFDataBindingLifecycleContextBuilder'.
    2009.26.3 20:12:52 oracle.adfinternal.controller.util.model.AdfmInterface initia
    lize
    INFO: ADFc: BindingContext is present, using ADFm APIs for DataControlFrames.
    2009.26.3 20:12:52 oracle.adfinternal.controller.metadata.provider.MdsMetadataRe
    sourceProvider <init>
    INFO: ADFc: Controller caching of MDS metadata resources ENABLED.
    2009.26.3 20:12:52 oracle.adf.controller.internal.metadata.MetadataService$Boots
    trap add
    INFO: ADFc: Loading bootstrap metadata from '/WEB-INF/adfc-config.xml'.
    2009.26.3 20:12:54 oracle.adf.share.security.providers.jps.CSFCredentialStore fe
    tchCredential
    WARNING: Unable to locate the credential for key AUGI in D:\bea\user_projects\do
    mains\base_domain\config\oracle.
    2009.26.3 20:12:54 oracle.adf.share.jndi.ReferenceStoreHelper throwPartialResult
    Exception
    WARNING: Incomplete connection information
    Edited by: Debuger on Mar 26, 2009 11:18 AM

  • Hi, recently purchased macbook 13", I have problem with sound when connect to my LG Smart tv with sound system. When i change sounds effect on my sound system also LG its all go quiet didn't have this problem with my laptop. Any advise ?

    Hi, recently purchased macbook 13", I have problem with sound when connect to my LG Smart tv with sound system. When i change sounds effect on my sound system also LG its all go quiet didn't have this problem with my laptop. Any advise ?

    Some progess I see. To be honest, i would not waste your time with trying to connect using wireless.
    You are likely to get poor connections and dropping out.
    If its working using a cable, then there is no need to bother with giving me the network settings, bu see how it goes, because sometimes giving the TV a static IP address can give better results.
    There is an example of a couple of powerline adapters on the diagram below. Just ignore the network switch unless you want to connect other devices which are near to the TV.
    http://forumhelp.dyndns.info/networking/powerline3.jpg
    I will monitor the subject line of this thread, should you want to post any more information.
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • I have a problem with Safari: when it opens and I go on google, it opens a page that says: PLEASE UPDATE INTERNET EXPLORERE.   What should I do?

    I have a problem with Safari: when it opens and I go on google, it opens a page that says: please update internet explorer!
    What should I do?

    It's a scam. Have a look at this thread:
    https://discussions.apple.com/thread/6058094?tstart=0

  • I have a problem with IDVD when I have completed a movie and set it up with menus etc I cannot operate the burn button so I cannot make a DVD.

    I have a problem with IDVD when I have completed a movie and set it up with menus etc I cannot operate the burn button so I cannot make a DVD.

    Hi
    Can You
    Go up to File Menu in iDVD - and here down to
    Save as a DiskImage
    If this works - You can burn Your DVD in another way via Disk Util tool
    Yours Bengt W

  • HT1338 Problem with MAIL, when select names that start with "E" the mail freeze. Can't fix it.

    Problem with MAIL, when select names that start with "E" the mail freeze. Can't fix it.

    Now I checked the materials that I got from AT&T Yahoo and
    port 25 is used as the outgoing mail port, 110 for incoming.
    This is for the POP type account provided by AT&T, not necessarily for an email account and SMTP server not provided by AT&T.
    Sounds like AT&T blocks using an SMTP server that is outside of their network or not provided by AT&T on Port 25.
    Try the following first.
    Go to Mail > Preferences > Accounts and under the Account Information tab for your .Mac account preferences at the SMTP server selection, select the Server Settings button below for the .Mac SMTP server.
    Enter 587 in place of 25 in the Server Port field and when finished, select OK to save the changed setting.
    If this doesn't work, we will go to plan B.

  • Help me, I have a problem with font when export report to PDF?

    Hi everyone! Help me
    I have a problem with font when export report to PDF
    My report uses template .rtf with font Times New Roman (Unicode), language is VietNamese.
    when desige template no problem, error only happen when view report by PDF.
    Edited by: user10236405 on Oct 15, 2008 11:23 PM

    give it time to boot. the time depends on yr memory size n data. soon a process bar will appear indicating the boot process. if still this doesnt work. try formating the phone. but this ways u lose all data on the phone (unless u backed it). relax! the data on the memory card is safe.

Maybe you are looking for

  • In Apple Mail, how can I maintaining Mailbox links when migrating hosting?

    First, I apologize if this question has already been asked and answered.  If so, please kindly point me to the appropriate discussion. I'm in the process of changing hosting for one of my (several) websites and email addresses.  I have been using App

  • With iCloud activated on iOS devices, how do I manage syncing with iTunes?

    Guess it's time to take a class at the Apple Store (there's an app for that) Two Questions: Question 1 I have turned on iCloud in my iPad and iPhone5 for contacts, calendars, reminders, Safari, Passbook (iPhone only), and Find my iPhone/iPad.  I am n

  • Questions about networking a desktop app

    So the background first: I'm working on a hobby program, and wanted to try my hand at networking it. It's a desktop app (a simple game) that two or more users can play at the same time. There's no centralized server to connect to, it will be an ad ho

  • External keyboard and modifier keys

    I like to swap my "Ctrl" and "Command" modifiers keys and I've never had a problem doing this until upgrading to Lion.  If I disconnect and reconnect my external keyboard sometimes my modifier keys are reset. Lion lets you change modifier keys per ke

  • Blank Screen on Ipod

    My ipod still works, but for some reason i cant see anything on the screen, theres a bunch of lines, and some black & white spaces on the screen when i turn on the ipod, and i cant listen to any of my music, i have tried everything, Reseting the ipod