Solved

Sql Sytnax

Posted on 2008-10-15
1
225 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
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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