Solved

Sql Sytnax

Posted on 2008-10-15
1
198 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now