Update and case when
In this scenario, we can use CASE expression. CASE expression is used for selecting or setting a new value from input values. In some cases we need to select and modify the record based on specific conditions. So instead of using cursor or looping, we can use case CASE expression.
Sagar Shinde Updated date Dec 20, I have SQL server Table in which there is column that I wanted to update according to a existing column value that is present in current row. The CASE expression has two formats,. The simple CASE expression compares an expression to a set of simple expressions to determine the result. Both formats support an optional ELSE argument. Do you get an error? What exactly is your problem? Does it update the wrong rows? Sorry for beeing so inaccurate.
The data type is Char. My bad. My problem is exactly what Adomar and Thomas is disussing below. Add a comment. Active Oldest Votes. Improve this answer. Thomas Thomas That would work, but the question seems to suggest that the OP has no control over the in string — Andomar. Andomar - Presumably, the OP has control over the case expression otherwise, how can they possibly fix it?
If that's the case, then it seems logical that they would have the ability to reformat the In clauses before they get put into the Case expression. If budgpost is really a character column as is stated, then we have to assume that a non-numeric value might make its way into one of the In clauses. Thomas: It's not uncommon for a DBA to have no control over the arguments passed by clients.
In this case the client might pass ,, or something. Not sure, the question can be interpreted either way. Andomar - But then how would they fix the Case expression? If they can change the Case expression, then they should be able to correct the values passed to the Case expression even if they cannot change which values are passed to it.
Andomar - Said another way, if I'm only able to correct the procedure which is passed an argument with values like 1,2,3. I can't change what I get passed, but I can take what I'm given and change it to '1','2','3'. Show 4 more comments. Andomar Andomar k 44 44 gold badges silver badges bronze badges. If you can change the in string, use Thomas' answer — Andomar. Gary Myers Gary Myers SriniV This query is overly complex and hard to understand.
Looks like you're making Oracle process string inputs inside a shell script. You should process the inputs before plugging them into the SQL. That would simplify the query — roblogic. Scott Scott 4 4 silver badges 7 7 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.
Post as a guest Name. Email Required, but never shown.
0コメント