Forum Replies Created

Viewing 15 posts - 496 through 510 (of 1,413 total)

  • Reply To: drop one row based on criteria

    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,...

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

  • Reply To: Need help resolving a SET based Query where I have hardcoded values

    with recent_cte(HorseName, FinishPosition, RaceDate, Rating) as (
    SELECT top 1 with ties HorseName, FinishPosition, RaceDate, Rating
    FROM @RACES
    ...

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

  • Reply To: String

    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...

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

  • Reply To: Using If Else condition in Merge Statement : SQL

    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...

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

  • Reply To: Cumulative Report

    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...

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

  • Reply To: Case Statement in where

    Maybe like this

    if @ItemGroup is null
    Select Itemcode,Itemname,ItemGroup
    from tbl1
    where itemgroup is null;
    else
    Select...

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

  • Reply To: Invalid column Name Hcode

    Maybe extract the constant and put the correlated subquery in the FROM clause as a CROSS APPLY

    declare @vmax_var         ...

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

  • Reply To: help with case statement

    Maybe a good way could be an UPDATE statement

    update t
    set flag = case when v.row_count=1 then 'ANY_EMPTY'
    ...

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

  • Reply To: How to sum on one value and not to sum on another value

    In the situation where Sum([QTY]) returns the correct the number, AVG(OH) or MAX(OH) ought to return only 1 SKU

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

  • Reply To: Error - Invalid column value ltotal,BAmt,Td

    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...

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

  • Reply To: concat + isnull

    Phil Parkin wrote:

    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...

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

  • Reply To: concat + isnull

    Jeff Moden wrote:

    Now, if they'd just add a machine language sequence generator to replace fnTally, create a BULK EXPORT, and create a truly useful xp_Dir...

    The DIY way could be to...

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

  • Reply To: concat + isnull

    Concat_ws was originally in MySQL then the other db's borrowed it iirc.  The big news for me is .NET 6 which I'm really liking a lot because it nicely untangles...

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

  • Reply To: concat + isnull

    CONCAT_WS() "concat with separator" ignores the nulls

    select concat_ws(' | ', t.Col1, t.Col2, t.Col3) [output]
    from #t t;

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

  • Reply To: Using GetDate in HAVING clause

    The date could be converted without using string functions.  Also, the WHERE clause might be a more appropriate place to filter the rows.  Maybe something this

    declare @UPSBatchInvNot...

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

Viewing 15 posts - 496 through 510 (of 1,413 total)