Solved

How can I execute an Immediate IF in a SQL statement? (t-SQL)

Posted on 2007-11-14
3
854 Views
Last Modified: 2010-04-21
I have a file, it has (5) check amount fields. I need to update the record with a field that will give the valid number of checks in the record.  The possibilities are; 2 checks, or 5 checks.  I can assume that if "check amount 3" has a zero value, expressed as '000.00' then it is a (2) check record, and if it is not '000.00' then it is a (5) check record.

I need to do this query along with several other updates at the same time.  Is there a way to do something along the lines of a (iif check_number_3 = '000.00,'2','5')? inside an update statement?
0
Comment
Question by:TommyMac501
[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 23

Assisted Solution

by:Snarf0001
Snarf0001 earned 50 total points
ID: 20284993
update <<tablename>> set <<columnname>> = case when check_number_3 = '000.00' then 2 else 5 end
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 75 total points
ID: 20285083
Best is to use a computed column, which SQL will not store but will automatically (re)compute every time you need to use the value.  For example:

ALTER TABLE tableName
ADD CheckCount AS CASE WHEN [Check Amount 3] = 000.00 THEN 5 ELSE 2 END

From then on, you can use CheckCount just like any regular column.
0
 

Author Closing Comment

by:TommyMac501
ID: 31409249
Thank you both, this solution worked great.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

696 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