Solved

IIF/CASE statement in a SQL Server VIEW

Posted on 2006-10-27
3
1,507 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

687 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