Solved

SQL IIF Statement in SSMS 2005

Posted on 2009-05-08
3
488 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 250 total points
Comment Utility
FeedBackTrue:=CASE WHEN columnname>=Value  THEN  1  ELSE 0  END
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
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
Comment Utility
Thank you so much!  I couldnt get the syntax right and it was driving me nuts!!!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 Copy Database Wizard 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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now