Solved

IIF/CASE statement in a SQL Server VIEW

Posted on 2006-10-27
3
1,502 Views
Last Modified: 2012-06-27
Experts, in my Select statement I want split a transaction column into credits and debits, in SQL Server.  I have opened the SQL Query Analyzer and typed:

CASE WHEN tran > 0 THEN tran ELSE 0 END as credits, CASE WHEN tran < 0 THEN abs(tran) ELSE 0 END as debits FROM transactions

And it works great...

But when I open a new VIEW and enter the same working code, I get an error: "The Query Designer does not support the CASE SQL construct."  And it won't allow me to save the view.  Is there a way I can do an IIF type statement in the Query Designer, that will actually let me save it as a VIEW?
0
Comment
Question by:AptDev
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
TommyTupa earned 450 total points
ID: 17823219
Try using  SQL Query Analyzer rather than the Query designer or enterprise manager which have limitations.

Open query analyzer and create a view with the syntax 'Create vew MyView as select....'

For example:

Use Northwind
Go
Create view my_View
as
select * from customers





0
 
LVL 5

Assisted Solution

by:nakul_vachhrajani
nakul_vachhrajani earned 50 total points
ID: 17833263
The following is working for me in a view in the production environment (I am substituting table names and column names with alphabets to protect privacy of the system).

SELECT a, b,
          (CASE c
            WHEN 1 THEN 'Yes'
            ELSE 'No' END) AS MyCase,
FROM MyTable
0
 
LVL 5

Expert Comment

by:nakul_vachhrajani
ID: 17833267
Also, as said by "TommyTupa", try creating views using the Query Analyzer.
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

685 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