Forum Replies Created

Viewing 15 posts - 16 through 30 (of 125 total)

  • RE: Remove a value from a union

    Jeff Moden (6/24/2015)


    Dohsan (6/24/2015)


    Execution plan puts #2 at a higher cost of the batch

    Just a bit of a sidebar here. The execution plan is a wonderful research tool...

  • RE: Remove a value from a union

    mister.magoo (6/24/2015)


    Alvin Ramard (6/24/2015)


    mister.magoo (6/24/2015)


    All these UNION queries will be scanning the table twice, yes?

    Each SELECT statement will cause the data to be read from the table.

    Yes, to be pedantic,...

  • RE: Remove a value from a union

    Not sure if the requirements here are getting mixed, hoping the two choices here will clear up what you want

    USE FF_Winning_Together;

    DECLARE @BaseData TABLE

    (

    LastName VARCHAR(20),

    FirstName VARCHAR(20)

    )

    INSERT INTO @BaseData(LastName,FirstName)

    VALUES('Apple','Bob'),

    ('Apricot','Jane'),

    ('Carrot','John'),

    ('Corn','Jon'),

    ('Eggplant','Ed'),

    ('Grape','Sam');

    --Omit Letters when no...

  • RE: Query SQL For New Table

    ags.saputra88 (6/24/2015)


    Thanks Mr Dohsan For Answer,

    I Have Trend Record Data Using SQL Server 2012, Data Collected By Other Program Use SQL Server.

    I Confuse Because Data Format Devided By Time Grouping,...

  • RE: Pivot, unpivot

    Would you have some example data for this with what your expected output would be?

    I thought it was just a standard pivot question until I reread what you were asking....

  • RE: Query SQL For New Table

    Below makes use of a "Cross Tab" which if you search for on this site you should find some articles detailing it.

    --Create Test Data

    WITH BaseData (TagName,Time_1,Data_1,Time_2,Data_2)

    AS

    (

    SELECTA.TagName,

    A.Time_1,

    A.Data_1,

    A.Time_2,

    A.Data_2

    FROM(

    VALUES('Test1',CAST('07:00' AS TIME),20,CAST('07:30' AS TIME),40),

    ('Test2',CAST('07:00'...

  • RE: Generate Combination of numbers

    double post

  • RE: Generate Combination of numbers

    serg-52 (6/19/2015)


    Dohsan (6/19/2015)


    Here's one using a recursive CTE, if I have time I'll have a go at a set based solution

    This will not produce correct result for the...

  • RE: Generate Combination of numbers

    Here's one using a recursive CTE, if I have time I'll have a go at a set based solution

    DECLARE @Chuff VARCHAR(8000) = 'NA,T1,T1a'

    DECLARE @SplitValues TABLE (Item VARCHAR(8000));

    INSERT INTO @SplitValues (Item)

    SELECTitem

    FROMdbo.DelimitedSplit8K(@Chuff,',');

    WITH...

  • RE: Generate Combination of numbers

    If the provided list of numbers will always have the same number of items, then something like this should work.

    DECLARE @Chuff VARCHAR(50) = 'NA,T1,T1a';

    ;WITH Test

    AS

    (

    SELECTItemNumber,

    Item

    FROMdbo.DelimitedSplit8K(@Chuff,',')

    )

    SELECTT.Item,

    T1.Item,

    T2.Item

    FROMTest AS T

    CROSS

    JOINTEST AS T1

    CROSS

    JOINTEST AS...

  • RE: Find appointments within 7 days, excluding weekends.

    NineIron (6/17/2015)


    Would you mind explaining how this works? I've separated the different "components" but can't figure it out. I know that it is dividing the number of days since 1/1/1900...

  • RE: db_name() return type : nvarchar(128)

    Great news that you've managed to fix it, would you also be able to share the solution? May be useful for others in the future.

  • RE: Calculate number of groups and group size with multiple criteria

    helal.mobasher 13209 (6/16/2015)


    Thank you for sharing the code. For most part, the code is working since I can get no of groups from your GroupNum column. However, GrpSize (GroupCount) should...

  • RE: Calculate number of groups and group size with multiple criteria

    Sure it can be done more efficiently than this, but this appears to work:

    WITH AddRank

    AS

    (

    SELECTGT.DT,

    GT.ClientID,

    GT.BegTime,

    GT.EndTime,

    GT.Duration,

    --Remove Partition by DT if you want times grouped regardless of day)

    BegRank = DENSE_RANK() OVER (PARTITION...

  • RE: Calculate number of groups and group size with multiple criteria

    pietlinden (6/15/2015)


    Please post consumable data -- in the form of CREATE TABLE/INSERT statements or a SELECT statement with UNIONS...

    http://www.sqlservercentral.com/articles/Best+Practices/61537/%5B/quote%5D

    I've generated some test data based on your attachment for...

Viewing 15 posts - 16 through 30 (of 125 total)