Forum Replies Created

Viewing 15 posts - 211 through 225 (of 1,438 total)

  • RE: convert all the column of table to ToBase64String

    There's an unpleasant XML conversion that may work for you

    WITH source AS (

    SELECT Deptid,Dept_name,location,HASHBYTES('MD5',CAST(Deptid AS VARCHAR(10)) + Dept_name + location) AS col

    FROM department)

    SELECT Deptid,Dept_name,location,

    ...

  • RE: Query to select records only when all records in group meets the same criteria

    Try this

    SELECT *

    FROM #Machine m

    WHERE m.MachineTypeFk = 99

    AND m.OnHand = 0

    AND m.Enabled = 0

    AND EXISTS(SELECT * FROM #MachineBranch mb WHERE mb.MachineFk = m.MachinePk)

    ...

  • RE: merge/flatten overlapping Time ranges. In order.

    Here's another version, this one using SQL Server 2012 LEAD

    WITH Source AS (

    SELECT *

    FROM

    (VALUES

    (1, 'A',convert(datetime,'20150101'),convert(datetime,'20150331')),

    (2, 'B','20150115','20150215'),

    (3, 'C','20150215','20150315'),

    (4, 'D','20150115','20150315'),

    (5, 'E','20150401','20150415')

    ) AS TimeIntervals(OrderId, status, DateStart, DateEnd)

    ),

    Starts AS (

    SELECT...

  • RE: merge/flatten overlapping Time ranges. In order.

    The problem is due to two intervals having a one day gap between the end of one and the start of the next, I think these can simply be excluded.

    Change

    CROSS...

  • RE: merge/flatten overlapping Time ranges. In order.

    It was getting the wrong values for ordereid and status in some circumstances.

  • RE: merge/flatten overlapping Time ranges. In order.

    tomek tomek (2/11/2015)


    Hi,

    First of all, thank you all for your input. It is invaluable.

    @venoym

    a) you solutions with numbers looks very interesting, but as Dwain suggested I had problems...

  • RE: merge/flatten overlapping Time ranges. In order.

    This works with your data, not very efficient though

    WITH Source AS (

    SELECT *

    FROM

    (VALUES

    (1, 'A',convert(datetime,'20150101'),convert(datetime,'20150331')),

    (2, 'B','20150115','20150215'),

    (3, 'C','20150215','20150315'),

    (4, 'D','20150115','20150315'),

    (5, 'E','20150401','20150415')

    ) AS TimeIntervals(OrderId, status, DateStart, DateEnd)

    ),

    Starts AS (

    SELECT a.DateStart...

  • RE: If minus figure pull back 0

    You can nest CASE expressions

    ,CASE WHEN com.completion_date IS NOT NULL AND dim.DayName <> 'Saturday'

    THEN CASE WHEN DATEDIFF(d, com.current_task_target_date,com.completion_date) < non1.NoWorkDays THEN 0 ELSE DATEDIFF(d, com.current_task_target_date,com.completion_date) - non1.NoWorkDays END

    WHEN com.completion_date...

  • RE: If minus figure pull back 0

    Use a CASE expression

    CASE WHEN MyColumn < 0 THEN 0 ELSE MyColumn END

  • RE: describing tree paths

    a20213 (2/5/2015)


    why you consider it odd ? i was reading a text on anti - pattern representations, that's from where i took the "idea" of this representation.

    Because there's a lot...

  • RE: describing tree paths

    Seems an odd representation of a hierarchy but this gives you the correct results

    WITH CTE AS (

    SELECT la.label AS ancestor,

    ...

  • RE: get xml text from varchar column

    Have you tried running my last query?

  • RE: get xml text from varchar column

    This is a bit of a guess...

    select t1.id,

    stuff((select ','+x.r.value('./text()[1]','nvarchar(max)') as "text()"

    from tblxmldata t2

    cross apply t2.xmltext.nodes('/associatedText/value') as...

  • RE: get xml text from varchar column

    Try this

    select stuff(

    (select ','+x.r.value('./text()[1]','nvarchar(max)') as "text()"

    from tblxmldata

    cross apply xmltext.nodes('/associatedText/value') as x(r)

    for xml path('')),1,1,'')

  • RE: get xml text from varchar column

    Assuming xmltext is of type XML

    select x.r.value('./text()[1]','nvarchar(max)') as AssociatedText

    from tblxmldata

    cross apply xmltext.nodes('/associatedText/value') as x(r)

Viewing 15 posts - 211 through 225 (of 1,438 total)