Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default SQL string question

    Hi all,

    I have a situation here. I have a table (Options) which has the following
    single record {field}={value}:-

    Quota=50 (smalllint)
    CarryFwd=1 (bit - can be 0 or 1)
    CarryFwdMax=20 (smallint)

    And I have a table (Users) which has the concerned field called AvailCredit
    as one of its fields.

    I would like to update the field AvailCredit based on the values in Options
    table as follows:-

    If Options.CarryFwd value is 0 then
    Users.AvailCredit will be changed to Options.Quota regardless of what it's
    initial value is.

    If Options.CarryFwd value is 1 then
    Users.AvailCredit will be changed to Options.Quota+(Users.AvailCredit or
    Options.CarryFwdMax, whichever is lower)

    How do I write the SQL string as a single execution without having to read
    and update each users record in the application's for...next loop? Is that
    possible?

    I'm using MS SQL for the database.

    Thanks!


    Ajak Guest

  2. Similar Questions and Discussions

    1. Another String Manipulation Question
      Let's say I have a variable like this: 12345432112347890 The characters in the variable will always be different, but my goal will always be...
    2. string question: how to append x zeros to get fixed lenght string?
      "Bob Barrows" <reb_01501@yahoo.com> wrote in message news:uuhVv4mcDHA.656@tk2msftngp13.phx.gbl... newstring = Right("0000000" & i,8) ;-p
    3. String question: Returning portion of string with words surrounding highlighted search term?
      I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string,...
    4. STRING FORMATTING QUESTION
      My question is regarding strings in php. I have this form in which the user fills in a description. The problem is that if the user uses any...
    5. string question
      i am a perl novice, and i have a really simple question. what is the easiest way to tell if a string begins with "Re: " (without the quotes)? ...
  3. #2

    Default Re: SQL string question

    Ajak wrote:
    > Hi all,
    >
    > I have a situation here. I have a table (Options) which has the
    > following single record {field}={value}:-
    >
    > Quota=50 (smalllint)
    > CarryFwd=1 (bit - can be 0 or 1)
    > CarryFwdMax=20 (smallint)
    >
    > And I have a table (Users) which has the concerned field called
    > AvailCredit as one of its fields.
    >
    > I would like to update the field AvailCredit based on the values in
    > Options table as follows:-
    >
    > If Options.CarryFwd value is 0 then
    > Users.AvailCredit will be changed to Options.Quota regardless of what
    > it's initial value is.
    >
    > If Options.CarryFwd value is 1 then
    > Users.AvailCredit will be changed to Options.Quota+(Users.AvailCredit
    > or Options.CarryFwdMax, whichever is lower)
    >
    This is off the top of my head so it is not tested.

    UPDATE u
    SET AvailCredit =
    CASE CarryFwd WHEN 0 THEN
    Quota
    ELSE
    CASE WHEN CarryFwdMax > Quota + AvailCredit THEN
    Quota + AvailCredit
    ELSE
    CarryFwdMax
    END
    END
    FROM Users u CROSS JOIN Options o

    HTH,
    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows Guest

Posting Permissions

  • You may not post new threads
  • You may 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