Solved

Select within update

Posted on 2006-11-06
11
221 Views
Last Modified: 2008-02-01
When am I missing in order to get the below working?

Update dbo.Name
Set CombineID = NULL
where
SELECT CombineID
from dbo.Name
GROUP By CombineID
Having count(CombineID)<=1
0
Comment
Question by:PeterErhard
  • 6
  • 5
11 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17887204
Hi PeterErhard,


Update dbo.Name
Set CombineID = NULL
where CombineID In (
SELECT CombineID
from dbo.Name
GROUP By CombineID
Having count(CombineID)<=1 )





Cheers!
0
 

Author Comment

by:PeterErhard
ID: 17887218
Thanks, but get this now:

Server: Msg 116, Level 16, State 1, Line 1
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17887226
can i know the exact query you tried ?
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:PeterErhard
ID: 17887232
As above and below:

Update dbo.Name
Set CombineID = NULL
where CombineID In (
SELECT CombineID, count(CombineID) as test
from dbo.Name
GROUP By CombineID
Having count(CombineID)<=1 )
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17887233
remove that Count(CombineID) from the inner query

Update dbo.Name
Set CombineID = NULL
where CombineID In (
SELECT CombineID
from dbo.Name
GROUP By CombineID
Having count(CombineID)<=1 )
0
 

Author Comment

by:PeterErhard
ID: 17887238
I need that, it's critical to the update statement.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17887248
PeterErhard,
> I need that, it's critical to the update statement.
 Can I know what you are trying to do ?  Where this is used  ?
I assume that the 'Test' value is used to update some other columns

Update a
Set CombineID = NULL
--, SomeOtherField  = t.Test
FROM dbo.Name A
INNER JOIN (
SELECT CombineID, count(CombineID) as test
from dbo.Name
GROUP By CombineID
Having count(CombineID)<=1 )T
ON A.CombineID = T.CombineID
0
 

Author Comment

by:PeterErhard
ID: 17887255
There's a field within the Name table named CombineID. If there are less or equal to 1 CombineID the same, then I want to set those CombineIDs to NULL.

and Nope, that's the full query.
0
 

Author Comment

by:PeterErhard
ID: 17887277
As an example, you could have CombineIDs like this:

1
2
4
1
6
8
5
23

Then are running the update statement it should finish up like this:

<<NULL>>
2
4
<<NULL>>
6
8
5
23
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 17887284
Did you try the Queries i have given
For testing purpose run this

BEGIN TRAN

SELECT CombineID, Count(*) as [Count]
from dbo.Name
GROUP By CombineID
Having count(CombineID)<=1

Update dbo.Name
Set CombineID = NULL
where CombineID In (
SELECT CombineID
from dbo.Name
GROUP By CombineID
Having count(CombineID)<=1 )

SELECT CombineID, Count(*) as [Count]
from dbo.Name
GROUP By CombineID
Having count(CombineID)<=1

ROLLBACK TRAN
0
 

Author Comment

by:PeterErhard
ID: 17887295
Thanks, worked perfectly :)
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

713 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