"Is this a good practice or there is a better way I can achieve this?"NOLOCK is usually a bad thing. Do you understand the potential issues you will face? Dirty data, missing data, data duplicated in the resultset etc?What is the problem you are trying to solve? (rather than your suggested solution
)I don't know quite how SQL will interpret your UPDATE phrase (this has come up here before, and I think the parser is "loose" on this!), but:UPDATE CR_CONSIGNMENT_CHARGES ASET InvoiceNo = @iInvoiceNo FROM CR_CONSIGNMENT_CHARGES AS A
would be unambiguous.AND ( ISNULL(@sChargeCode,'') = '' OR ( ISNULL(@sChargeCode,'') <> '' AND A.ChargeCode = @sChargeCode ))
could be replaced by(ISNULL(@sChargeCode,'') = '' OR A.ChargeCode = @sChargeCode)
I don't know if it makes any difference to the Query Optimiser, but its a bit easier to read.JOIN CR_CLIENTS C ON C.Code = CASE ISNULL(A.ChargeAccount,'') WHEN '' THEN B.ClientChargeCode ELSE A.ChargeAccount END
can be replaced (I think!) withJOIN CR_CLIENTS C ON C.Code = ISNULL(A.ChargeAccount, B.ClientChargeCode)
but it is still not very efficient, although probably more efficient than a CASE statement.