Solved

SQL IIF Statement in SSMS 2005

Posted on 2009-05-08
3
499 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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 we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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