Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to write this access query in MS SQL

Posted on 2011-04-25
4
Medium Priority
?
211 Views
Last Modified: 2012-06-27
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
Comment
Question by:ubsmail
4 Comments
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 35463936
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
 
LVL 8

Accepted Solution

by:
Ghunaima earned 2000 total points
ID: 35464778
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
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 35464995
Select

CatIDs.GoogleTax1 + (case when GoogleTax2 is null or GoogleTax2='' then '' else ' > ' end) +GoogleTax2)
0
 

Author Closing Comment

by:ubsmail
ID: 35469260
Thanks all
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question