Skip to main content
nikos101
Inspiring
December 5, 2008
Question

For one column I need some logic, return null in select

  • December 5, 2008
  • 5 replies
  • 737 views
I have a query where I want to select stuff but for one column I need some logic

select a,b,c, { if (a=b ) return null, else return a - c} as d

I don't know how to do this,

Any ideas?

This topic has been closed for replies.

5 replies

Inspiring
December 5, 2008
> can anyone see what's wrong with this:

You are missing the case END
Inspiring
December 5, 2008
my suggestion is to get your sql working first, and then put it into your sp.
nikos101
nikos101Author
Inspiring
December 5, 2008
Oh btw I'm trying some complex stuff but getting errors,can anyone see what's wrong with this:

declare @amount float
set @amount = (
case when @b = 'B' then
(select SUM(a) from t ) else

(select SUM(c) from t)
)
nikos101
nikos101Author
Inspiring
December 5, 2008
Worked a treat thanks
Inspiring
December 5, 2008
select case
when a = b then null
else a-c
end as d