** This SQL statement returns 4 rows
SELECT
COUNT(*)
G.ACTIVITY_ID
G.RESOURCE_TYPE
G.RESOURCE_CATE GORY
G.RESOURCE_SUB_ CAT
G.ANALYSIS_TYPE
G.PROJECT_ID
FROM PS_SOI_COAMAP F with (nolock)
, PS_SOI_CNV_TMP0 60 G with (nolock)
WHERE F.BUSINESS_UNIT = '00300'
AND F.BUSINESS_UNIT = G.BUSINESS_UNIT
AND F.ACTIVITY_ID = G.ACTIVITY_ID
AND F.RESOURCE_TYPE = G.RESOURCE_TYPE
AND F.RESOURCE_CATE GORY = G.RESOURCE_CATE GORY
AND F.RESOURCE_SUB_ CAT = G.RESOURCE_SUB_ CAT
AND F.ANALYSIS_TYPE = G.ANALYSIS_TYPE
AND F.PROJECT_ID = G.PROJECT_ID
AND F.PROJECT_ID = '300FW0WILD0750 3'
GROUP BY G.ACTIVITY_ID
,G.RESOURCE_TYP E
,G.RESOURCE_CAT EGORY
,G.RESOURCE_SUB _CAT
,G.ANALYSIS_TYP E
,G.PROJECT_ID
HAVING COUNT(*) > 1
** Now I want to Update table G where the criteria in the previous query is met. So I attempt to use WHERE EXIST, but I update all rows in table G instead of the 4 rows from the previous query. Can anyone tell me what I am doing wrong? Thanks in advance.
UPDATE PS_SOI_CNV_TMP0 60
SET SOI_FLAG = 'D'
WHERE EXISTS (
SELECT
COUNT(*)
, G.ACTIVITY_ID
, G.RESOURCE_TYPE
, G.RESOURCE_CATE GORY
, G.RESOURCE_SUB_ CAT
, G.ANALYSIS_TYPE
, G.PROJECT_ID
FROM PS_SOI_COAMAP F with (nolock)
, PS_SOI_CNV_TMP0 60 G with (nolock)
WHERE F.BUSINESS_UNIT = '00300'
AND F.BUSINESS_UNIT = G.BUSINESS_UNIT
AND F.ACTIVITY_ID = G.ACTIVITY_ID
AND F.RESOURCE_TYPE = G.RESOURCE_TYPE
AND F.RESOURCE_CATE GORY = G.RESOURCE_CATE GORY
AND F.RESOURCE_SUB_ CAT = G.RESOURCE_SUB_ CAT
AND F.ANALYSIS_TYPE = G.ANALYSIS_TYPE
AND F.PROJECT_ID = G.PROJECT_ID
AND F.PROJECT_ID = '300FW0WILD0750 3'
GROUP BY G.ACTIVITY_ID
,G.RESOURCE_TYP E
,G.RESOURCE_CAT EGORY
,G.RESOURCE_SUB _CAT
,G.ANALYSIS_TYP E
,G.PROJECT_ID
HAVING COUNT(*) > 1 )
1 2240 Delerna 1,134
Recognized Expert Top Contributor
according to the SQL servers help documentation
here is the code to update a table from another table -
UPDATE titles
-
SET t.ytd_sales = t.ytd_sales + s.qty
-
FROM titles t, sales s
-
WHERE t.title_id = s.title_id
-
-
so to update from a query, write your query
and do something like this. -
UPDATE titles
-
SET t.ytd_sales = t.ytd_sales + s.qty
-
FROM titles t, myQueryName s
-
WHERE t.title_id = s.title_id
-
If you don't want to have a separate query then wrap the query up in brackets
and include it directly in the update query. -
UPDATE titles
-
SET t.ytd_sales = t.ytd_sales + s.qty
-
FROM titles t, (SELECT Title_ID,Qty FROM Sales) s
-
WHERE t.title_id = s.title_id
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums must be UPDATED, if not, they
must be INSERTED.
Logically then, I would like to SELECT * FROM <TABLE>
WHERE ....<Values entered here>, and then IF FOUND
UPDATE <TABLE> SET .... <Values entered here> ELSE
INSERT INTO <TABLE> VALUES <Values...
|
by: rrh |
last post by:
I am trying to update a field in one table with data from another
table. The problem I'm running into is I need to base the update on a
range of data in the 2nd table.
Table 1 has:
date field
new field
table 2 has:
key field (autonumber)
|
by: Dom Boyce |
last post by:
Hi
First up, I am using MS Access 2002.
I have a database which records analyst rating changes for a list of
companies on a daily basis. Unfortunately, the database has been set
up (by my predecessor, I hasten to add) so that each day it creates a
copy of the record for each company, changes the date to today's date,
and prompts the user for any changes of ratings on that day. The
resulting data table grows by approx 600 records per...
|
by: sheree |
last post by:
I have 3 tables (amoung a few others) in a small access database. The
tables are as follows:
==
AEReport
--------
AEID (PK)
RptCatelog
GCRCID
PatientID
EvntDate
|
by: Maxi |
last post by:
There is a lotto system which picks 21 numbers every day out of 80
numbers.
I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21)
Here is the structure and sample data:
"Date","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15","P16","P17","P18","P19","P20","P21"
1/1/2005,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21
1/2/2005,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
| |
by: Bob |
last post by:
Hi all,
I want to incorporate several types of different rankings to a Make
Table Query I have then use the rank for calculations.
I want to calculate rankings based on how much each client has in a
portfolio, so lets say there are 4 portfolios, so each client would
have 4 rankings, dependant upon how much they had in each portfolio
compared to their peers. I then want to use each of those rankings to
run some calculations. I want all...
|
by: Riun |
last post by:
Hi,
I'm trying to run an update query in vba and i'ts not working. It does the update but the field is updated to "-1".
here's the query:
Dim stDocName As String
Set rst = New ADODB.Recordset
stDocName = "SELECT * FROM WHERE =" & txtID.Value & ""
|
by: ARC |
last post by:
Hello all,
So I'm knee deep in this import utility program, and am coming up with all
sorts of "gotcha's!".
1st off. On a "Find Duplicates Query", does anyone have a good solution for
renaming the duplicate records? My thinking was to take the results of the
duplicate query, and somehow have it number each line where there is a
duplicate (tried a groups query, but "count" won't work), then do an update
query to change the duplicate to...
|
by: Arved Sandstrom |
last post by:
This seems to be something so simple that none of the hundred-odd tutorials
and forum threads that I have looked at (:-)) apparently thinks it's a
problem.
In a nutshell, I have two DataGridViews. Each has a BindingSource (and a
BindingNavigator). The first view populates successfully based upon a Linq
to SQL query in the Form Load (that is, the query is assigned to the
DataSource of that view's BindingSource, and the BindingSource is...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |