Solved

Select within update

Posted on 2006-11-06
11
219 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

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