Forum Replies Created

Viewing 15 posts - 376 through 390 (of 1,413 total)

  • Reply To: Calculate a new field in SQL statement

    It's only 2 rows of data.  To test with different cases I added some additional rows.  Afaik you're looking to conditionally apply the sum of invoiceid credits from 'creditmemo' to...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: SQL server help

    It seems you're looking for the COALESCE function.  If the empty values are stored as '' then NULLIF returns NULL.  COALESCE returns the first (left to right of the parameter...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Parse SQL data

    To split out the pd_id's you could try STRING_SPLIT to separate based on space delimiter.  Since some 'PD-[0-9]' values are encompassed by other extra characters a conditional substring is done...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Previous Week data to current week data

    Thanks to Jeff Moden in this thread for the function used here

    In row 1 of the expected output from which input table does the Rnge value 45 come from? ...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Please help to get, Alphabet with underscore i.e special charecter

    Jeff Moden wrote:

    THAT, good Sir, is a beautiful thing!  All you need to do now is give the author of that good function a little credit by citing the article where...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Please help to get, Alphabet with underscore i.e special charecter

    Afaik this actually produces the desired output.  Should work with SQL 2014.  It uses the ordinal splitter DelimitedSplit8K_Lead.  The query: splits the input string on '_' underscore, finds the offset...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Please help to get, Alphabet with underscore i.e special charecter

    Instead of a WHILE loop you could try a numbers table or tally function approach

    declare @string varchar(255) = 'EMA_20210526T211254_0000_MRNMM0000001240_PMS110460PAT000001287_PID15235307_OR_Dr';

    select string_agg(v.chr, '') within group (order by fn.n)...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: SQL MAX of multiple columns?

    These two statements are equivalent afaik.  Beginning with [Edit] 2022 (or compatibility level 150 in Azure SQL) they added the GREATEST function.  Prior ways were UNPIVOT using the built-in verb...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Put result of one query into another

    planetmatt wrote:

    Is there  a reason to do the Cross Apply rather than just doing the addition calculation directly in the UPDATE SET ?

    The value 'calc.adjusted_minutes' is referenced twice in the...

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

  • Reply To: Incorrect syntax near 0

    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

  • Reply To: sql retrieve information after second occurrence of a character

    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

  • Reply To: sql retrieve information after second occurrence of a character

    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

  • Reply To: Quick SQL challenges for mid-experienced+ DBAs (and advanced T-SQLers)

    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

  • Reply To: Quick SQL challenges for mid-experienced+ DBAs (and advanced T-SQLers)

    Jeff Moden wrote:

    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

  • Reply To: Group by column over partition ordered by date

    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

Viewing 15 posts - 376 through 390 (of 1,413 total)