473,468 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Updating a table if another tables row matches... not sure if that quite explains it.

1 New Member
I have 2 tables in my SQL Server (These were created by Microsoft CRM)

Table 1 is ActivityPointerBase (po for short)
Table 2 is ActivityPartybase (pa for short)

First:

Loop begins with grabbing the first row from po.
IF TypeCode = 4201 great! Start the second loop
grab the first row of pa and test
if po.activityID = pa.activityID AND po.OwningUser = pa.ActivityPartyID
Then we set the pa.ParticipationTypeMask = 7
Otherwise, endif and goto next row
If TypeCode did not equal 4201 we would go to the next row.

I've got the idea down, I know how it SHOULD work. I just do not know how to code it so that it WILL work. I keep getting random errors on all of my attempts.

Any ideas?

thanks,

Ken
Apr 25 '07 #1
1 1303
pkreemer
13 New Member
Hi kwcraft, you can do this with a SQL update statement. Just to be sure, TypeCode is in the po table?

Try this:

Expand|Select|Wrap|Line Numbers
  1. UPDATE ActivityPartybase 
  2.    SET  ParticipationTypeMask = 7
  3.       FROM ActivityPointerBase po
  4.          WHERE 
  5.             po.TypeCode = 4201 
  6.             AND po.activityID = ActivityPartybase.activityID
  7.             AND po.OwningUser = ActivityPartybase.ActivityPartyID
You describe your algorithm in a procedural way and SQL works in a different, set-oriented manner. So you just have to translate. It's not always as easy as this but I think the SQL above is what you want.

I did not test it with dummy tables, so let me know if I got something wrong!

Paul
Apr 25 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
4
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5...
6
by: Geoff | last post by:
Hi This question has just occurred to me and I'm hoping somebody can help me. Suppose I have a table in an Access database. I have access to this table via a data adaptor i.e. I create a data...
1
by: Gunnar | last post by:
I am finding some unusual behavior with techniques I am using to show/hide/update data without having to refresh the page. I'm quite sure it's developer ignorance on my part and would be grateful...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
14
by: John T Ingato | last post by:
I have a contacts table with name address and such but are missing all phone numbers in the phone number fields. I have just received an updated customer list in Excel and have imported into a new...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
0
by: oh4real | last post by:
I recently developed a compact function to efficiently allow users to change info in a form (like account info, contact info, etc.) and then the function automatically identifies what's changed and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.