Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL IIF Statement in SSMS 2005

Posted on 2009-05-08
3
Medium Priority
?
508 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
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2

885 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