July 14, 2015 at 8:51 am
Welsh Corgi (7/13/2015)
I can copy and paste but not the whole line when I try and scroll.Could you please place the code outside of the CQL Code Tag?
Thanks.:-)
It might be easier to start the copy at the end of the line before the code block, and to end it at the beginning of the line after the code block.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
July 14, 2015 at 9:26 am
click at the start
scroll to the end
shift click
July 14, 2015 at 9:42 am
Welsh Corgi (7/13/2015)
drew.allen (7/13/2015)
ISNULL() requires an opening paren and the subquery also requires an opening paren. You are trying to conflate them. You also have the second argument of the ISNULL() in the middle of the subquery.
update #tmpTotals SET StateCount = ISNULL((SELECT SUM(DayCount) FROM #tmpTotals t WHERE Loss_state = #tmpTotals.Loss_State ), 0)
Drew
Hi Drew,
I can't copy sand paste the code.:blush:
UPDATE #tmpTotals
SETStateCount = ISNULL(( SELECT SUM(DayCount)
FROM #tmpTotals t
WHERE Loss_state = #tmpTotals.Loss_State
), 0);
How's this format? Should be much easier to copy/paste! You just have to highlight and scroll down now.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
July 14, 2015 at 11:40 am
With all the talk about copy/paste of the code, I have the ask the obvious. Do you understand how the code works? If you don't understand what it's doing, then don't use it. Wayne's signature says it all - you'll be the one supporting it. Make sure you understand what you copy/paste from the internet.
July 14, 2015 at 11:45 am
Ed Wagner (7/14/2015)
With all the talk about copy/paste of the code, I have the ask the obvious. Do you understand how the code works? If you don't understand what it's doing, then don't use it. Wayne's signature says it all - you'll be the one supporting it. Make sure you understand what you copy/paste from the internet.
Wayne's code does come with a money back guarantee though!
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
July 14, 2015 at 11:53 am
SQLRNNR (7/14/2015)
Ed Wagner (7/14/2015)
With all the talk about copy/paste of the code, I have the ask the obvious. Do you understand how the code works? If you don't understand what it's doing, then don't use it. Wayne's signature says it all - you'll be the one supporting it. Make sure you understand what you copy/paste from the internet.Wayne's code does come with a money back guarantee though!
And you get what you pay for also!
July 14, 2015 at 12:03 pm
Lynn Pettis (7/14/2015)
SQLRNNR (7/14/2015)
Ed Wagner (7/14/2015)
With all the talk about copy/paste of the code, I have the ask the obvious. Do you understand how the code works? If you don't understand what it's doing, then don't use it. Wayne's signature says it all - you'll be the one supporting it. Make sure you understand what you copy/paste from the internet.Wayne's code does come with a money back guarantee though!
And you get what you pay for also!
Sorry, but I must disagree. I think we get a whole lot more than we pay for on SSC.
July 14, 2015 at 12:16 pm
Welsh Corgi (7/13/2015)
What is wrong with the following Statement?
update #tmpTotals set StateCount = (Select ISNULL Sum(DayCount),0) from #tmpTotals t where Loss_state = #tmpTotals.Loss_State )
As the first responder indicated, it's just a missing parenthesis for the ISNULL function.
UPDATE #tmpTotals
SET StateCount = (
SELECT ISNULL(SUM(DayCount),0)
FROM #tmpTotals AS t
WHERE t.Loss_state = #tmpTotals.Loss_State
)
If that can't be copied, here's the plain text:
UPDATE #tmpTotals
SET StateCount = (
SELECT ISNULL(SUM(DayCount),0)
FROM #tmpTotals AS t
WHERE t.Loss_state = #tmpTotals.Loss_State
)
Enjoy...
EDIT: Corrected query based on Gail Shaw's (aka GilaMonster) subsequent post.
Steve (aka sgmunson) π π π
Rent Servers for Income (picks and shovels strategy)
July 14, 2015 at 12:23 pm
Apart from your syntax error (which i have not checked)
what's the purpose of comparing same column from same table?
..."WHERE Loss_state = #tmpTotals.Loss_State"
July 14, 2015 at 12:35 pm
SolveSQL (7/14/2015)
Apart from your syntax error (which i have not checked)what's the purpose of comparing same column from same table?
..."WHERE Loss_state = #tmpTotals.Loss_State"
That's used to get a correlated subquery and get the proper value for each row instead of a single value for all rows in the table.
July 14, 2015 at 1:26 pm
SolveSQL (7/14/2015)
what's the purpose of comparing same column from same table?..."WHERE Loss_state = #tmpTotals.Loss_State"
He's not.
The table inside the subquery is aliased as t and the binding order for columns is to first check tables inside the subquery and then tables outside, so the comparison is bound as
WHERE t.Loss_state = #tmpTotals.Loss_State
It should have been written with the column explicitly qualified for safety.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 15, 2015 at 1:46 am
Instead of updating the temp table, why not calculate the value when you populate it, like this:
SUM(DayCount) OVER(PARTITION BY Loss_State)
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
July 15, 2015 at 7:27 am
Makes sense. Thanks.
July 16, 2015 at 8:00 am
Try triple-clicking inside the CQL Code Tag.
Viewing 14 posts - 16 through 28 (of 28 total)
You must be logged in to reply to this topic. Login to reply