Forum Replies Created

Viewing 15 posts - 241 through 255 (of 1,396 total)

  • Reply To: Bad data - updating date from new FK

    All right it sounds tedious.  To differentiate the duplicates you're looking to add 1, 2, 3, ... n hours to the datetime column, EffectiveDate.  Of course, this could create new...

  • Reply To: How to add couple more conditions to the query

    Maybe 3 WHERE clause conditions could be sufficient (A and B or C):

    A) the existing criteria

    B) NOT College ID 06 under Municipality 25002

    C) municipal_ID equals 4269005 (which would be inclusive...

  • Reply To: Finding duplicates based on count on different fields

    Or it could be 5 or ?

  • Reply To: Finding duplicates based on count on different fields

    In conclusion I would recommend a crosstab-type query.  Conventions of language don't always map to relational operators.  And often predictably so.  Language conventions that is.    Are you sure you're...

  • Reply To: SSIS C# Script Question

    Just scanning the code and there are nested Try/Catch and a transaction is declared but rollback only appears in 1 of the TRY code blocks.  That's concerning imo.  Could you...

  • Reply To: SSIS C# Script Question

    Maybe throw a general exception and write your own error message.  Or the method returns void so maybe just "return;"?

  • Reply To: Grouping the first letter in a string

    Per SQL 2022 you could try STRING_SPLIT with the optional ordinal parameter and then recombine using STRING_AGG

    drop table if exists #temp
    go
    select *
    into #temp
    from (values ('First American...
  • Reply To: Help with calculating Percentages

    It turns out, upon further review, a non-INT as either the numerator OR the denominator will switch the implicit conversion to NUMERIC.

    select sql_variant_property(1/4, 'basetype') int_int,
    ...
  • Reply To: Swapping coordinate pairs round

    Needs the XML trick to reaggregate the string

    declare @string varchar(max)='-0.326548;51.75514;-0.32658;51.75507;-0.326261;51.755;-0.326231;51.75508;-0.326548;51.75514;';

    select *
    from dbo.DelimitedSplit8K_LEAD(@string, ';') ss
    cross apply (values (iif(ss.ItemNumber%2=0, ss.ItemNumber-1, ss.ItemNumber+1))) v(new_seq);

    select stuff((select ' ' + ss.Item
    ...
  • Reply To: Help with calculating Percentages

    Instead of dividing by 100 try dividing by 100.0.  With division the implicit type conversion is to INT unless the denominator is non-INT, either NUMERIC or FLOAT.  Also, imo the...

  • Reply To: BASE64 Encode and Decode in T-SQL

    For posterity since 2012 the built-in method for converting to base64 is using XML.  This comes up every now and then on SSC.  The only post I could find tho...

  • Reply To: First Two Words

    Already had dbo.fnTally.  Here are the results which show 7 or 8 seconds for CHARINDEX and 33+ seconds for STRING_SPLIT.  This is my tiny Azure SQL compatibility level 150 test...

  • Reply To: First Two Words

    Jonathan AC Roberts wrote:

    I don't think calling complicated string_split and string_agg functions will be more efficient than calling simple string functions.

    Maybe so.  Can your chatbot make the case for it?  Splitting and...

  • Reply To: First Two Words

    Imo davidandrews13 has the right idea.  In SQL 2022

    select string_agg(sv.[value], ' ') within group (order by sv.ordinal) first2_in_order
    from #temp t
    cross apply (select...
  • Reply To: Replace function not working

    Could be a type mismatch due to the search string not being specified with the Unicode prefix N'...'

    declare @json nvarchar(max)=N'Array ( [error] => Quote not found [module]...

Viewing 15 posts - 241 through 255 (of 1,396 total)