[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

update a column within a join statement and group by clause

Posted on 2013-11-04
6
Medium Priority
?
233 Views
Last Modified: 2013-11-05
I have pulled up the following recordset.

SELECT Max(Text4)Text4,Max(Text5)Text5, Sum(Total)TotalsperStudent FROM AttendanceGrid INNER JOIN tblRegistration ON AttendanceGrid.[ID]=tblRegistration.[ID] Where  AttendanceGrid.Fiscal = '" & Fiscal & "' And AttendanceGrid.[CSW/TitleXX] = 'C' And AttendanceGrid.Month = '" & Com(z) & "' And NewPart = 0 And Combo11 like '" & rec1.Fields(0) & "' Group by tblRegistration.ID HAVING Sum(Total)>0

Open in new window


Within this recordset, I would like to update the column called NewPart = 1 in the table called AttendanceGrid.  

How is this possible?
0
Comment
Question by:al4629740
  • 2
  • 2
  • 2
6 Comments
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39622973
update AttendanceGrid set NewPart = 1 Where AttendanceGrid.[ID] in (SELECT Max(Text4)Text4,Max(Text5)Text5, Sum(Total)TotalsperStudent FROM AttendanceGrid INNER JOIN tblRegistration ON AttendanceGrid.[ID]=tblRegistration.[ID] Where  AttendanceGrid.Fiscal = '" & Fiscal & "' And AttendanceGrid.[CSW/TitleXX] = 'C' And AttendanceGrid.Month = '" & Com(z) & "' And NewPart = 0 And Combo11 like '" & rec1.Fields(0) & "')
0
 

Author Comment

by:al4629740
ID: 39623293
Sorry, I meant to say "NewPart = 1 in the table called tblRegistration.

Would it be:

update AttendanceGrid set NewPart = 1 Where tblRegistration.[ID] in (SELECT Max(Text4)Text4,Max(Text5)Text5, Sum(Total)TotalsperStudent FROM AttendanceGrid INNER JOIN tblRegistration ON AttendanceGrid.[ID]=tblRegistration.[ID] Where  AttendanceGrid.Fiscal = '" & Fiscal & "' And AttendanceGrid.[CSW/TitleXX] = 'C' And AttendanceGrid.Month = '" & Com(z) & "' And NewPart = 0 And Combo11 like '" & rec1.Fields(0) & "')
0
 

Author Comment

by:al4629740
ID: 39623457
I tried the following with no success:

update tblRegistration set NewPart = 1 Where tblRegistration.[ID] in (SELECT * FROM AttendanceGrid INNER JOIN tblRegistration ON AttendanceGrid.[ID]=tblRegistration.[ID] Where  AttendanceGrid.Fiscal = '2013' And AttendanceGrid.[CSW/TitleXX] = 'C' And AttendanceGrid.Month = 'September' And NewPart = 0 And  Total > 0 And Combo11 like 'Alternatives')

Error:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Assisted Solution

by:QuinnDex
QuinnDex earned 400 total points
ID: 39623566
try this

update tblRegistration set NewPart = 1 Where exists tblRegistration.[ID] in (SELECT * FROM AttendanceGrid INNER JOIN tblRegistration ON AttendanceGrid.[ID]=tblRegistration.[ID] Where  AttendanceGrid.Fiscal = '2013' And AttendanceGrid.[CSW/TitleXX] = 'C' And AttendanceGrid.Month = 'September' And NewPart = 0 And  Total > 0 And Combo11 like 'Alternatives')
0
 
LVL 12

Expert Comment

by:Paul_Harris_Fusion
ID: 39623855
update tblRegistration set NewPart = 1
where ID in
(
SELECT tblRegistration.ID
FROM AttendanceGrid INNER JOIN tblRegistration
ON AttendanceGrid.[ID]=tblRegistration.[ID]
Where  
AttendanceGrid.Fiscal = '" & Fiscal & "'
And AttendanceGrid.[CSW/TitleXX] = 'C'
And AttendanceGrid.Month = '" & Com(z) & "'
And NewPart = 0
And Combo11 like '" & rec1.Fields(0) & "'
Group by tblRegistration.ID
HAVING Sum(Total)>0  
)
0
 
LVL 12

Accepted Solution

by:
Paul_Harris_Fusion earned 1600 total points
ID: 39623860
Or specifically with your runtime values:

update tblRegistration set NewPart = 1
Where ID in
(
SELECT tblRegistration.ID
FROM AttendanceGrid INNER JOIN tblRegistration
ON AttendanceGrid.[ID]=tblRegistration.[ID]
Where  AttendanceGrid.Fiscal = '2013'
And AttendanceGrid.[CSW/TitleXX] = 'C'
And AttendanceGrid.Month = 'September'
And NewPart = 0
And  Total > 0
And Combo11 like 'Alternatives'
)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

831 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