Viewing 15 posts - 391 through 405 (of 1,419 total)
It appears to be a nonworking attempt at a catch all query. Imo the easy answer is two procedures or however many are necessary. In this case imo the OP...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 10, 2022 at 12:27 pm
Since the current code uses REPLACE with strings of equal length followed by LEFT(8), it's equivalent to SUBSTRING(input_string, 38, 8)
select v.in_str, substring(v.in_str, 38, 8) inv_num
from (values ('Company...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 7, 2022 at 5:13 pm
You could try the PATINDEX function and look for the first occurrence of 8 consecutive integers enclosed in parentheses. Instead of typing the criteria 8 times this uses REPLICATE. The...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 7, 2022 at 1:01 pm
select cast(year(v.sort_mo) as smallint), input_str.mo
from (values ('Jan'),('Feb'),('Mar'),
('Apr'),('May'),('Jun'),
...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 6, 2022 at 2:21 am
Steve Collins wrote:Here's 1, 3, and 4
I was going to test this for performance but then noticed that it's not a complete answer 😮
The data types were added. It says:...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 6, 2022 at 1:48 am
You could try something like this
with rn_cte as (
select *, case when row_number() over (partition by [Itinerary] order by [CreationDate])=1 and LegSegment is...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 5, 2022 at 11:01 pm
Here's 1, 3, and 4
--(1)
select v.sort_mo, input_str.mo
from (values ('Jan'),('Feb'),('Mar')) input_str(mo)
cross apply (values (parse(concat(input_str.mo, '-01-1900') as date))) v(sort_mo)
order by v.sort_mo;
--(3)
declare @b ...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 5, 2022 at 7:54 pm
It's an interesting approach Drew. As I see it it's a partial self-CROSS JOIN then summarize instead of summarize then index JOIN. My suspicion was confirmed using Jeff's test harness...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 5, 2022 at 5:08 pm
The input from Excel are key value pair(s)? Suppose the inputs were inserted into a temporary SQL Server table. Would/could it look something like this?
create table ...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 3, 2022 at 11:37 pm
Nice catch yes I changed/fixed from:
where s.transactiondate > dateadd(month, -3, dt.t_dt)
to:
where s.transactiondate > eomonth(dt.t_dt, -3)
Using EOMONTH could still be considered risky if the...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 1, 2022 at 6:17 pm
The top query has 4x fewer logical reads. The issue afaik with with combining GROUP BY and CROSS APPLY in a single SELECT statement is the logical reads are based...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 1, 2022 at 5:24 pm
This query returns no rows
with
gaps_cte(CalDate, [DayName] ,BusinessDay, Multiplier, Comment, gap) as (
select *, case when BusinessDay<>lag(BusinessDay) over (order by CalDate) then 1...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
June 29, 2022 at 10:24 pm
This is a classic "gaps and islands" type situation imo. Not sure what's going on with SSC tho. There's no text editor and the font is really tiny...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
June 29, 2022 at 12:26 pm
The function dbo.fnTally can be found and explained here
CREATE FUNCTION [dbo].[fnTally]
/**********************************************************************************************************************
Jeff Moden Script on SSC: https://www.sqlservercentral.com/scripts/create-a-tally-function-fntally
**********************************************************************************************************************/
...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
June 27, 2022 at 2:25 pm
To make more realistic (I guess) I added an additional row to t2 so the split requires 3 rows instead of 2. Also, I added a UNIQUE CLUSTERED INDEX on...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
June 27, 2022 at 2:10 pm
Viewing 15 posts - 391 through 405 (of 1,419 total)