SQL problem Part Deux

mjburgard
mjburgard used Ask the Experts™
on
I am having difficulty getting the following logical progression to work in SQL.
 
 If Master_variable = null or 'none'
   then insert Calculated_variable into DependentVariable
   else insert Calculated_variable2 into dependentVariable

Open in new window


Can anybody point me down the correct path?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
IF COALESCE(@master_variable, 'none') = 'none'
    SET @DependentVariable = @Calculated_variable
ELSE
    SET @DependentVariable = @Calculated_variable2
Top Expert 2011
Commented:
select @dependentvariable
          =case when @master_variable is null
                         or @master_variable ='none'
                    Then @calculated_variable
                    else @calculated_variable2
                    end
Top Expert 2010
Commented:
mjburgard,

Please note that my IF syntax does not work within a SELECT, INSERT, UPDATE, or DELETE statement; for those situations you need to use CASE as Lowfatspread demonstrates.

IF works, but only as a flow of control structure within a SQL batch.

Patrick

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial