Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

UPDATE Does Nothing (Executing Query displays in status) Expand / Collapse
Author
Message
Posted Thursday, October 04, 2012 12:58 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, April 14, 2013 12:31 PM
Points: 112, Visits: 394
I am stumped and perplexed.
The following statement executes correctly returns 2 Rows:

select JobNum, RefreshDate, RecID from ClosedJobsSumms

When this statement is executed nothing happens - the status shows Executing Query and the timer is clicking off the seconds.

UPDATE cjs
SET RefreshDate = '20120822 08:00'
FROM ClosedJobsSumms cjs

Other UPDATES have worked. For example, this executes OK, in a blink, so I know the UPDATE does execute on the table:
UPDATE cjs 
SET QtyOrdered = QtyOrds.qtyord
FROM ClosedJobsSumms cjs
INNER JOIN (SELECT o.job_number,
Sum(o.qty_ordered) AS QtyOrd
FROM ERPDB.dbo.orders o
LEFT JOIN ClosedJobsSumms cjs1
ON cjs1.jobnum = o.job_number
WHERE cjs1.jobnum IS NOT NULL
AND cjs1.custid IS NULL
GROUP BY o.job_number) QtyOrds
ON QtyOrds.job_number = cjs.jobnum





"The Road To Success Is Always Under Construction."
Post #1368650
Posted Thursday, October 04, 2012 1:04 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 3:07 PM
Points: 138, Visits: 355
whats the schema for closedJobSums?
Post #1368655
Posted Thursday, October 04, 2012 1:06 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439, Visits: 9,569
Unless there's something else blocking the update, it should run like that.

I just ran this test:

CREATE TABLE #T (
JobNum INT,
RefreshDate DATETIME,
RecID INT);

INSERT INTO #T (JobNum, RefreshDate, RecID)
VALUES (1,GETDATE(), 1),(2,GETDATE(),2);

UPDATE T
SET RefreshDate = '20120822 08:00'
FROM #T T;

SELECT *
FROM #T;

Worked just fine.

Try running this while your update is running:

exec sp_who2;

See if something is blocking the update.


- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #1368656
Posted Thursday, October 04, 2012 1:14 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 7:03 AM
Points: 2,979, Visits: 4,389
IF what you want to accomplish is to update every single row on CJS table then update should look like:

UPDATE cjs
SET RefreshDate = '20120822 08:00';



_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #1368661
Posted Thursday, October 04, 2012 1:18 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, April 14, 2013 12:31 PM
Points: 112, Visits: 394
Are you asking for: dbo
i.e. dbo.ClosedJobsSumms
All the other tables created in this DB are dbo.


"The Road To Success Is Always Under Construction."
Post #1368662
Posted Thursday, October 04, 2012 1:49 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, April 14, 2013 12:31 PM
Points: 112, Visits: 394
Problem Resolved: It was a PICNIC - Problem In Chair, Not In Computer

I had run an UPDATE on the table earlier in another query window, but, had not COMMITted it.

Discovered this problem when I decided I would close SSMS and start fresh. When closing the other query window I was notified that there were uncommitted transactions. Once COMMITted, the statement ran OK. Interesting the other statement in my post ran - 0 Rows Effected. It didn't occur to me until now it would 'execute' OK, since no records being updated meant the locked records would not have been involved.

I did run the sp_who2; I'm not familiar with this sp, can intuitively understand the information in the columns. Did not see anything indicating uncommitted transactions. Not sure what phrase/term would indicate as such.

Pablo - I wrote the statement that way because I am trying to get familiar with that structure. Repetition.

Thank You All For Your Help. My apologies for my error.


"The Road To Success Is Always Under Construction."
Post #1368679
Posted Friday, October 05, 2012 1:56 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 7:40 PM
Points: 1,059, Visits: 1,150
Hi,

It should be
UPDATE table_name
SET RefreshDate = '20120822 08:00';

rather than
UPDATE cjs
SET RefreshDate = '20120822 08:00';

else it will throw error
Post #1368865
Posted Friday, October 05, 2012 2:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:21 AM
Points: 5,602, Visits: 10,950
kapil190588 (10/5/2012)
Hi,

It should be
UPDATE table_name
SET RefreshDate = '20120822 08:00';

rather than
UPDATE cjs
SET RefreshDate = '20120822 08:00';

else it will throw error


Almost, but not quite. The OP's statement is
UPDATE cjs
SET RefreshDate = '20120822 08:00'
FROM ClosedJobsSumms cjs

and it's absolutely fine. It's known as UPDATE FROM, and it's typically used to update a table with data from another and / or update a table filtered by a join with another.


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1368871
Posted Friday, October 05, 2012 2:43 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, April 14, 2013 12:31 PM
Points: 112, Visits: 394
It's known as UPDATE FROM, and it's typically used to update a table with data from another and / or update a table filtered by a join with another.


I realize that even though typical structure would be 'UPDATE {table-name} SET ...' when that is sufficient I am now using the structure below for 2 reasons. The 1st, as I had expressed, to get familiar with it when the situation is as you mentioned and now, from a tip I read yesterday morning, to easily check before/after performing an UPDATE:

--SELECT
-- {column-names...}
UPDATE {table-name-alias}
SET ...
FROM {table-name}
...

"Toggle" Commented out lines to quickly switch between viewing and updating:
SELECT
{column-names...}
--UPDATE {table-name-alias}
--SET ...
FROM {table-name}
...



"The Road To Success Is Always Under Construction."
Post #1368877
Posted Friday, October 05, 2012 2:50 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:21 AM
Points: 5,602, Visits: 10,950
EdA ROC (10/5/2012)
It's known as UPDATE FROM, and it's typically used to update a table with data from another and / or update a table filtered by a join with another.


I realize that even though typical structure would be 'UPDATE {table-name} SET ...' when that is sufficient I am now using the structure below for 2 reasons. The 1st, as I had expressed, to get familiar with it when the situation is as you mentioned and now, from a tip I read yesterday morning, to easily check before/after performing an UPDATE:

--SELECT
-- {column-names...}
UPDATE {table-name-alias}
SET ...
FROM {table-name}
...

"Toggle" Commented out lines to quickly switch between viewing and updating:
SELECT
{column-names...}
--UPDATE {table-name-alias}
--SET ...
FROM {table-name}
...



Absolutely spot on.
There's no good reason - ever - for failing to check the SELECT version of an UPDATE FROM (or "joined update") and this makes it trivial to do.


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1368884
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse