Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF THEN ELSE Help??

Status
Not open for further replies.

Idokyoku2

Technical User
May 16, 2004
57
US
Hello,
I need some assistance with my IF Statement. Mostly familar with ANSI IFs. I understand SQL Server syntax is a bit different, but have little experience with it. This should be very simple for one of you.

My sample:

SELECT * FROM TBL1
IF PMTHD = 'BOFA-VISA'
BEGIN
UPDATE TBL1
SET PMTHD = 'VISA-BOFA'
END
ELSE PMTHD

Also, if anyone can refer a good book for someone looking to tweek their syntax so that it conforms to MS SQL Server.

David




 
looks like you just want to an update

Code:
update tbl1
set pmthd = 'VISA-BOFA'
where pmthd = 'BOFA-VISA'
 
I know update, delete, create, drop, constraints, indexes, etc., but having some trouble with ifs and loops.

Would you be able to provide a solution to my example?

Thanks,
David
 
You don't need an If or a loop in this case. Checkai's code shouold do the job.

And you should avoid looping altogether. It is a bad practice.

IF cannot be used within a select, Update, Delte or insert statment. In T-SQL, IF is procedural code and must be outside the query. If you need to evaluate conditions and do diffent things within a query based on a value, then you use the CASE statement. Look this up in BOL for more information.

Questions about posting. See faq183-874
Click here to learn Ways to help with Tsunami Relief
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top