Forum Replies Created

Viewing 15 posts - 1 through 15 (of 15 total)

  • RE: Simple CLR request

    Shouldn't be too hard using Linq...

    using System.Linq;

    [Microsoft.SqlServer.Server.SqlFunction(FillRowMethodName = "clrNGLoop_FillRow", TableDefinition = "Position int, Token nvarchar(4000)")]

    public static IEnumerable clrNGLoop(SqlString...

  • RE: Remove first 2 digit and change phonenumber format SQL

    Example below using a CASE statement

    Assuming phone numbers are entirely numeric:

    ;

    WITH PhoneNumbers AS (

    SELECT *

    FROM (

    VALUES ( 911234567891 ),( 1234567891 ),( 911234567891 ),( 1234567891 )

    ) PhoneNumbers(Number)

    )

    SELECT FORMAT( X.Number, '###-###-###' )

    FROM...

  • RE: Calculate Maximum three values from table in SQL

    Not sure about your Id standard, but if you can extract it then you could use DENSE_RANK

    E.g.

    SELECT ID

    FROM

    (

    SELECT *, DENSE_RANK( ) OVER ( ORDER BY CAST( RIGHT( ID, LEN(...

  • RE: Find Duplicate Records in Table and Update one of them.

    Depending on number of rows, and indexes etc... but I would usually do a "GROUP BY" to identify dupes together with MIN to identify original record, then joining back onto...

  • RE: Question create XML from SQL for XML format

    This is one way of doing it.

    DECLARE @Customers TABLE ( Col1 varchar(50), Col2 varchar(50), Col3 varchar(50) )

    INSERT INTO @Customers ( Col1, Col2, Col3 )

    VALUES ( 'Value from Col1 in Table...

  • RE: Insert values into single record

    Yeah, loop is a bad idea.

    I think the data represents a month (even though he's limited it to 30 )...my guess is he's trying to pivot the data

    E.g.

    --assuming data is...

  • RE: How to set the Flag for Only one Record

    I notice that you're looking for multiple seasons for same ID

    I.e. If ID has both Season16 and Season 15 then Flag is 0 else 1.

    Since row with id = 3...

  • RE: Add two proc Logic in to single query - Help needed

    Change "CONVERT(VARCHAR(8), MAX(PA.LastModifiedDate, 112)) AS DateSent"

    to "CONVERT(VARCHAR(8), MAX(PA.LastModifiedDate), 112) AS DateSent"

  • RE: Add two proc Logic in to single query - Help needed

    So much looks wrong with so little...

    From what I can see:

    - In your first procedure, Change to "GROUP BY", and return MAX( PolicyAudit.LastModifiedDate ) - made assumption that LastModifiedDate increases...

  • RE: Max value in Case Statements

    I'd probably use a CROSS APPLY in this instance...

    e.g.

    WITH Data AS

    (

    SELECT 1 AS ID, '1/1/1900' AS Date

    UNION ALL SELECT 2, '1/1/1900'

    UNION ALL SELECT 3, getdate()

    UNION ALL SELECT 4, Getdate()

    )

    SELECT D.*,...

  • RE: how to evaluate a string is true ??

    I think I understand what you're after, I also think your approach is wrong. But if you're really stuck, sounds like you need to dynamically work out the dynamic SQL...

  • RE: Inclusive Query Question

    Not sure what you're after, but is this it?

    create table #Target(id int, TargetID int, ItemID varchar(3), Target int)

    insert into #Target

    select 1,1,'ABC',5 union all

    select 2,1,'CBA',90 union all

    select 3,1,'DAB',5

    create table #Actuals(id int,...

  • RE: Help with COUNT

    Little late, but...

    here's another approach comparing min and max values...

    SELECT CASE WHEN MIN_JobNumber = MAX_JobNumber THEN 'One EndPoint' ELSE '2+ EndPoint' END, SUM(x)

    FROM (SELECT 1 x, MIN(JobNumber) MIN_JobNumber, MAX(JobNumber) MAX_JobNumber...

  • RE: How to Missing Date range??

    Had some spare time, here's a solution to your problem.

    I think results are correct, hope solution isn't too long winded.

    results selected are:

    empid       Missing dates description

    ----------- ------------- -----------

    1           01...

  • RE: DateTime Query

    Don't know if this is still relevant for you, but output of following query will give you the required SQL statements:

    SELECT 'SELECT * FROM [' + sysU.name + '].[' +...

Viewing 15 posts - 1 through 15 (of 15 total)