Viewing 15 posts - 481 through 495 (of 1,402 total)
Suppose there's an ordinal column called 'Ord'. The WHERE clause makes sure the "first" row is a "root" ElementID. The OUTER APPLY selects the ElementID to substitute if the row...
December 26, 2021 at 1:48 pm
Say I have a table that allows nulls on some columns. As records are added, some columns are filled only say 20% of the time. is there an easy...
December 25, 2021 at 3:08 pm
It doesn't seem possible without additional information. In your FIRST_VALUE function the PARTITION BY patid and ORDER BY elementiddate doesn't seem to deterministically define the order of the rows where...
December 25, 2021 at 3:05 pm
delete p
from #pat p
where p.ElementID='B'
and exists(select 1
...
December 24, 2021 at 5:04 pm
Maybe a DELETE statement like this. [Edit: got rid of window function approach and went with COUNT(*) ]
with rn_cte(PatID, ElementIDDate) as (
select PatID,...
December 23, 2021 at 5:55 pm
with recent_cte(HorseName, FinishPosition, RaceDate, Rating) as (
SELECT top 1 with ties HorseName, FinishPosition, RaceDate, Rating
FROM @RACES
...
December 23, 2021 at 1:39 pm
Following on what Mr. Brian Gale wrote about a DELETE causing a massive gap in the IDENTITY property of a table. It happens sometimes because things which aren't good sometimes...
December 22, 2021 at 6:13 pm
Based on the code I would guess your ExceptionLog table is empty because the error handling issues the ROLLBACK before the error values are accessed. But it's not really guaranteed...
December 17, 2021 at 12:59 pm
It's a great answer from Jeff which exactly matches the output. My approach also uses Jeff's "number generator" function dbo.fnTally. While Jeff "didn't use any of your dates" (because it's...
December 16, 2021 at 1:51 pm
Maybe like this
if @ItemGroup is null
Select Itemcode,Itemname,ItemGroup
from tbl1
where itemgroup is null;
else
Select...
December 15, 2021 at 2:06 pm
Maybe extract the constant and put the correlated subquery in the FROM clause as a CROSS APPLY
declare @vmax_var ...
December 15, 2021 at 1:43 pm
Maybe a good way could be an UPDATE statement
update t
set flag = case when v.row_count=1 then 'ANY_EMPTY'
...
December 14, 2021 at 6:44 pm
In the situation where Sum([QTY]) returns the correct the number, AVG(OH) or MAX(OH) ought to return only 1 SKU
December 12, 2021 at 4:59 pm
At a minimum it's missing a comma at the end of the first line. Is it necessary to nest SELECT statements within the SELECT list as you've done? It seems...
December 11, 2021 at 2:52 pm
Yup, I was one of the 'most people' crowd, thanks for alerting me to that, Jeff. Always good to be aware of these extra possibilities. It was also only...
December 9, 2021 at 2:52 pm
Viewing 15 posts - 481 through 495 (of 1,402 total)