Forum Replies Created

Viewing 15 posts - 1,441 through 1,455 (of 3,957 total)

  • RE: Build menu with CTE ....

    PiMané (9/23/2013)


    dwain.c (9/23/2013)


    As Jeff said, NM=Nice Method (?).

    Except I think that P.[Path] should be p.Order_val in the recursive leg of your CTE.

    Yes, had to change it to work...

  • RE: Build menu with CTE ....

    hunchback (9/22/2013)


    One way to accomplish this is using a varbinary column to concatenate the sequence of numbers based on the position value.

    WITH C1 AS (

    SELECT

    Id, IdRoot, Name, Position,

    CAST(ROW_NUMBER() OVER(ORDER...

  • RE: Get the Maximum Value from a related table based on date

    Charlottecb (9/23/2013)


    Hi dwain.c,

    Yep that works for me - I'll scale up my data to see how it performs against the other solutions.

    Many thanks for responding.:-D

    You are welcome and thanks for...

  • RE: How to Write Query for This

    Something like this perhaps?

    WITH SampleData ([Key], Col1, Col2) AS (

    SELECT 1, 'ABC', 'DEF'

    UNION ALL SELECT 2, 'GFI', 'XYZ')

    SELECT Col1=MAX(CASE WHEN [Key]=Key1 THEN...

  • RE: How to get exact values for a constraint in SQL Server??

    The parsing isn't so bad if you use a pattern splitter function and all of your constrains are like this IN type.

    WITH CheckConstraint ([definition]) AS (

    select...

  • RE: Get the Maximum Value from a related table based on date

    Does this work for your case?

    WITH Orders AS

    (

    SELECT *

    ,rn=ROW_NUMBER() OVER (PARTITION BY CustomerID ORDER BY OrderID DESC)

    ...

  • RE: Passing Type Table as parameters into Function

    I agree that passing in a subquery for the TYPEd table instead of having to predefine the table would be nice but as you have ascertained, SQL doesn't support it...

  • RE: T-SQl help...

    Not sure but perhaps this is a simpler approach?

    CREATE TABLE #tTable(

    sk int NOT NULL IDENTITY UNIQUE CLUSTERED,

    CID INT,

    CDate DATETIME,

    Dept VARCHAR(10)

    );

    INSERT INTO #tTable(CID, CDate, Dept)

    VALUES

    (111,'2012-10-05 00:00:00.000','A'),

    (111,'2012-10-18 00:00:00.000','C'),

    (111,'2012-11-01 00:00:00.000','B'),

    (111,'2012-11-01...

  • RE: Are the posted questions getting worse?

    Lynn Pettis (9/21/2013)


    hisakimatama (9/21/2013)


    Lynn Pettis (9/21/2013)


    Well, by reading The Thread from start to now you also got to learn some interesting things about many of the regulars here on SSC....

  • RE: Tally Tables

    Don Cureton (9/19/2013)


    I seem to remember getting an error without a partition statement

    ROW_NUMBER() does not require a PARTITION clause.

    Some of the other window aggregates, e.g., MAX(xx), MIN(xx), AVG(xx), do.

  • RE: Day of week comparison for contact availability

    kevin 32621 (9/19/2013)


    Thanks Dwain that worked great. Now on to the next thing to bang my head against the wall for! 😀

    Kevin

    You need what I have, which is a vibration...

  • RE: Day of week comparison for contact availability

    kevin 32621 (9/19/2013)


    Well, that's a good question. I'm still relatively new to sql server and all it's nuances, especially dynamic stuff. So I'm not sure how to make this work...

  • RE: Day of week comparison for contact availability

    Do you mean something like this?

    WITH SampleData (MyDate, StartTime, EndTime) AS (

    SELECT '2013-09-20 08:20', '09:00', '11:00'

    UNION ALL SELECT '2013-09-20 09:20', '09:00', '11:00'

    ...

  • RE: Ignoring parenthesis in a name field

    I agree with MM that simply knowing PATINDEX, CHARINDEX and SUBSTRING and playing around a bit, you should be able to construct a working solution.

    Another alternative if you are inclined...

  • RE: Day of week comparison for contact availability

    A little DDL and sample data would have helped, but in this case it was easy enough to generate.

    DECLARE @Contacts TABLE

    (

    ContactID INT IDENTITY PRIMARY...

Viewing 15 posts - 1,441 through 1,455 (of 3,957 total)