Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Enthusiast ,
Dec 05, 2008 Dec 05, 2008
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?

TOPICS
Database access
717
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 05, 2008 Dec 05, 2008
select case
when a = b then null
else a-c
end as d
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 05, 2008 Dec 05, 2008
Worked a treat thanks
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 05, 2008 Dec 05, 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)
)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 05, 2008 Dec 05, 2008
my suggestion is to get your sql working first, and then put it into your sp.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 05, 2008 Dec 05, 2008
LATEST
> can anyone see what's wrong with this:

You are missing the case END
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources