• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

How to write this access query in MS SQL

How can I write this query to do the same function in SQL

Select

CatIDs.GoogleTax1 + IIf(IsNull(GoogleTax2) or GoogleTax2='','',' > '+GoogleTax2) + IIf(IsNull(GoogleTax3) or GoogleTax3='','',' > '+GoogleTax3) + IIf(IsNull(GoogleTax4) or GoogleTax4='','',' > '+GoogleTax4) + IIf(IsNull(GoogleTax5) or GoogleTax5='','',' > '+GoogleTax5) + IIf(IsNull(GoogleTax6) or GoogleTax6='','',' > '+GoogleTax6) as GoogleTax

from products
 
0
ubsmail
Asked:
ubsmail
1 Solution
 
Aaron TomoskySD-WAN SimplifiedCommented:
As I'm on my phone I'm not going to type a working version but here is an outline.  Basically use case instead of iff
Select (googletax1
case when googletax2 is null then '' else +', '+googletax2 endcase
0
 
GhunaimaCommented:
What is CatIDs.googletax1??? Other than that Try This

Select
CatIDs.GoogleTax1 +
case when IsNull(GoogleTax2, '')='' then '' else ' > '+GoogleTax2 end + case when IsNull(GoogleTax3, '')='' then '' else ' > '+GoogleTax3 end + case when IsNull(GoogleTax4,'')='' then '' else ' > '+GoogleTax4 end + case when IsNull(GoogleTax5, '')='' then '' else ' > '+GoogleTax5 end + case when IsNull(GoogleTax6, '')='' then '' else ' > '+GoogleTax6end as GoogleTax
from products

Select
CatIDs.GoogleTax1 + 
case when IsNull(GoogleTax2, '')='' then '' else ' > '+GoogleTax2 end + case when IsNull(GoogleTax3, '')='' then '' else ' > '+GoogleTax3 end + case when IsNull(GoogleTax4,'')='' then '' else ' > '+GoogleTax4 end + case when IsNull(GoogleTax5, '')='' then '' else ' > '+GoogleTax5 end + case when IsNull(GoogleTax6, '')='' then '' else ' > '+GoogleTax6end as GoogleTax 
from products

Open in new window

0
 
Alpesh PatelAssistant ConsultantCommented:
Select

CatIDs.GoogleTax1 + (case when GoogleTax2 is null or GoogleTax2='' then '' else ' > ' end) +GoogleTax2)
0
 
ubsmailAuthor Commented:
Thanks all
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now