Professional Web Applications Themes

CASE in UPDATE? - Microsoft SQL / MS SQL Server

Hi, i want to update my Customer table in my SQLServer database. I want to check whether each field in the table has a value assigned to it - if it does, i want to check whether the new value (the one that the user wants to put in the field) is null/0 or not. If it is null/0, i want to keep the old value. If not, the field should be updated. If the field is null (or 0 for integers) to start off with, the update should also be completed. Can anyone help me with this UPDATE? I ...

  1. #1

    Default CASE in UPDATE?


    Hi,

    i want to update my Customer table in my SQLServer database. I want to
    check whether each field in the table has a value assigned to it - if it
    does, i want to check whether the new value (the one that the user wants
    to put in the field) is null/0 or not. If it is null/0, i want to keep
    the old value. If not, the field should be updated. If the field is null
    (or 0 for integers) to start off with, the update should also be
    completed.

    Can anyone help me with this UPDATE? I am guessing i can use CASE....but
    i don't know how.

    Would be grateful for any help!

    /Lis

    --
    Posted via http://dbforums.com
    betski Guest

  2. #2

    Default Re: CASE in UPDATE?


    Thanks, Dean.

    I'll give it a try!

    Lis

    --
    Posted via http://dbforums.com
    betski Guest

  3. #3

    Default CASE in UPDATE?

    Here is my solution using a trigger:

    create triger ins_mytable on mytable for insert,Update as

    BEGIN
    ---Check all fields to see if they contain a value
    IF (not isnull(select field1 from mytable)... and not
    isnull(select field10 from mytable))
    ---If all fields contain a value check newvalue
    ---newvalue must not be null
    IF (not isnull(select field1 from inserted... and isnull
    (select field10 from inserted))
    ELSE
    Rollback
    END
    ELSE
    Rollback
    END

    HOPE THAT HELPS 
    database. I want to 
    assigned to it - if it 
    the user wants 
    want to keep 
    the field is null 
    also be 
    use CASE....but 
    Guest

Similar Threads

  1. How to use CASE with UPDATE?
    By EranMagen in forum Coldfusion Database Access
    Replies: 5
    Last Post: August 13th, 04:44 PM
  2. Is there a way to convert lower case text to upper case text in PHP?
    By tanas@ing.com.au in forum PHP Development
    Replies: 3
    Last Post: December 11th, 06:12 AM
  3. #23026 [Com]: Make Zend case-sensitive (classes, functions, remove case-insensitive)
    By nvivo at mandic dot com dot br in forum PHP Development
    Replies: 0
    Last Post: October 19th, 12:17 PM
  4. 5.0.7 Update Pack 1 requires SCO Update license?
    By Scott McMillan in forum SCO
    Replies: 0
    Last Post: July 30th, 08:04 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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139