Solved

SQL IIF Statement in SSMS 2005

Posted on 2009-05-08
3
501 Views
Last Modified: 2012-05-06
I already have a query that returns data that i need for a report in SSMS 2005.  I need to generate a column named 'FeedbackTrue' to the already returned data set.  I want this column to contain only 1's and 0's.  

In Access under query designer, i would have just wrote a formula like FeedBackTrue:=IIF(columnname>=Value, 1,0) and then i would have my column of data.

How do i do this query designer within SQL Server Mgmt Studio 2005 under query designer.

I pasted my current query, and i want to base the new column off the value of the CreatedDate column.
SELECT DISTINCT 
                      TblUsers.PK_Users, TblDepartment_lookup.DepartmentName, TblUsers.FullName, TblFeedback.CreatedDate
FROM         TblDepartment_lookup INNER JOIN
                      TblUsers ON TblDepartment_lookup.PK_Department = TblUsers.FK_Department LEFT OUTER JOIN
                      TblFeedback ON TblUsers.PK_Users = TblFeedback.FK_User
GROUP BY TblDepartment_lookup.DepartmentName, TblUsers.FullName, TblFeedback.CreatedDate, TblUsers.PK_Users
ORDER BY TblDepartment_lookup.DepartmentName, TblUsers.FullName

Open in new window

0
Comment
Question by:szadroga
[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
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 24339095
FeedBackTrue:=CASE WHEN columnname>=Value  THEN  1  ELSE 0  END
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24339102
FeedBackTrue:=IIF(columnname>=Value, 1,0)

translates in SQL into:

CASE WHEN columnname>=Value THEN  1 ELSE 0 END FeedBackTrue  
0
 

Author Closing Comment

by:szadroga
ID: 31579592
Thank you so much!  I couldnt get the syntax right and it was driving me nuts!!!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

634 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