Forum Replies Created

Viewing 15 posts - 601 through 615 (of 1,413 total)

  • Reply To: How to calculate the outcome based on multiple records for same Customer

    On second thought, instead of individually calculating the decimal costs they could be added all together into one value 'dCost'.  Also, a combination of TRY_CAST and ISNULL could be used...

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

  • Reply To: How to calculate the outcome based on multiple records for same Customer

    The obligatory comment is regarding the problems arising from storing numeric data as varchar instead of decimal(#, #).  Assuming you're stuck with the DDL you could try something like this. ...

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

  • Reply To: Need T-SQL revised to show 3rd column

    It appears you're looking for $137,000 less the running total of yearly license costs.  Also, the 'money' data type is imprecise and has serious issues so this uses decimal(14, 2)...

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

  • Reply To: T-SQL to find id waiting each hour

    Simplified using OUTER APPLY instead of the LEFT JOIN

    with
    max_min_cte(t_min_dt, t_max_dt) as (
    select min(dateadd(hour, datediff(hour, 0, start_dt), 0)),
    ...

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

  • Reply To: T-SQL to find id waiting each hour

    This uses a tally function (or it could be called a "numbers function") twice.  Once, to generate the total hourly datetime range across all rows in table #t.  Second, to...

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

  • Reply To: help with SQL script

    select *, dateadd(hour, datediff(hour, 0, in_datetime), 0) out_datetime
    from #data;

    [EDIT] Same answer as Ant-Green but 2 minutes later 🙂

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

  • Reply To: Need help on Substring

    select left(isnull(stuff(first_name, 11, 3, '...'), first_name), 13) 
    from @t1;

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

  • Reply To: Sum field with where clause based on a RecordId

    Another alternative could be CROSS APPLY

    update t
    set AmountAll = ca.sum_amount
    from #test t
    cross apply (select sum(tt.Amount)
    ...

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

  • Reply To: Importing a CSV into SQL Server Shouldn't Be This Hard

    As long as people are sharing their CSV secrets.  Warning disclosure this contains C# code.  A couple of years ago I worked on a project for a fitness tracking system...

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

  • Reply To: Help with code

    Jeff Moden wrote:

    Could you post the CREATE TABLE statement for your date table?  I'd like to try a couple of things.

    To start with maybe the OP could use a rental periods...

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

  • Reply To: Choosing two fields from only the two most rec the first and second records only

    Another alternative using kaj's set up data

    with cc_cte(cc1, cc2) as (
    select iif(row_number() over (order by Timestamp desc)=1, CallCount, 0) cc1,
    ...

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

  • Reply To: Are the posted questions getting worse?

    Thom A wrote:

    The tone of this response has changed significantly since the notification email I got, with its contents. I was going to remind you that sites like this have "points"...

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

  • Reply To: Are the posted questions getting worse?

    Welp, it seems worthwhile mentioning reputation points in an online forum, i.e. Stack Overflow, are a good way to enhance your resume.

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

  • Reply To: Tally OH! An Improved SQL 8K “CSV Splitter” Function

    Jeff Moden wrote:

    But before we even think of getting started on this, let's NOT do it here.  Let's open a separate thread and have the OP provide some reasonable sample data...

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

  • Reply To: Tally OH! An Improved SQL 8K “CSV Splitter” Function

    There are some caveats which should've been mentioned.  The string is declared as NVARCHAR(MAX) because I don't know that that's not appropriate.  The ordinal splitter is name '%8K_LEAD' because it's...

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

Viewing 15 posts - 601 through 615 (of 1,413 total)