Monday, March 26, 2012

Insert, Calculations & Where

Hi

I sometimes find myself in the situation where I want to insert a row into a table using the following form:
insert table ( <field list> ) select <field list> from .. etc .. Where <conditions>

My question is to do with where one or more of the fields in the select field list are calculations and where I also want to use some/all of these derived fields as Where conditions. [ Eg: only insert if the calculated value is > 0]

I currently either repeat the calculation in the Where clause or move it to a function and use the function call in both places. (I always get a pang of guilt using either option - repeating the calculation feels like bad practice - & using the function twice seems inefficient (does this get optimised?)).

I could get a life & stop worrying - but is there a better/neater way of doing this?

Many thanks.An exact DML sample would be helpful here...but if you need to INSERT a derived field, and need to make sure that the derived field is > 0 for example, then you have no choice...|||Use HAVING clause|||Use HAVING clause

Is it 5:00 already in texas?

No comments:

Post a Comment