Solved

Sql Sytnax

Posted on 2008-10-15
1
236 Views
Last Modified: 2012-05-05
Hello I need help with an update statment.
Table1: LinkID, Width, Height, UserID, Status
Table2: UserID, Credits

How can i do something like If Width * Height < Credits Then Set Status = 22.
I need to do this for each record in Table1 which is why Im having trouble writing it myself.

Thanks
0
Comment
Question by:grogo21
[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
1 Comment
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 22727224
update t1
set status = case when (width * height) < credits then 22 else t1.status end
from table1 t1
join table2 t2 on t1.userid = t2.userid

or, you can do it this way (probably the better approach, as only the records that meet your criteria are updated.)

update t1
set status = 22
from table1 t1
join table2 t2 on t1.userid = t2.userid
where  (width * height) < credits
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

628 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