Forum Replies Created

Viewing 15 posts - 4,216 through 4,230 (of 10,144 total)

  • RE: Trying to select the last 3 months of data

    ;WITH base AS (

    SELECT Max_DM = MAX(post_dm) FROM ztb_forecastable_metrics_hist

    )

    SELECT

    post_dm -- etc

    FROM ztb_forecastable_metrics_hist

    WHERE post_dm BETWEEN DATEADD(mm,-3,base.Max_DM) AND base.Max_DM

    GROUP BY Post_DM

  • RE: Need help with TSQL

    Since the sortorder column isn't particularly useful, why don't you populate it with the sort order that you actually want?

  • RE: Table data in tabular form

    -- sample data

    DROP TABLE #LeaveEntry

    CREATE TABLE #LeaveEntry(

    [LeaveId] [int] NOT NULL,

    [Name] [varchar](50) NOT NULL,

    [LeaveTypeName] [varchar](100) NOT NULL,

    [StartDate] [datetime] NULL,

    [EndDate] [datetime] NULL

    )

    SET DATEFORMAT YMD

    INSERT INTO #LeaveEntry VALUES

    (1, 'A','OUT','2013-08-12 00:00:00.000','2013-08-14 00:00:00.000'),

    (2, 'B','LON','2013-08-13 00:00:00.000','2013-08-14...

  • RE: Splitting Comma Separated Values into Rows

    Use APPLY to "encapsulate" a splitter function - in this case DelimitedSplit8k[/url];

    DECLARE @t Table

    (

    AreaID int,

    AreaName nvarchar(100),

    Responsible nvarchar(100)

    )

    Insert Into @t

    Select 1, 'Finance',Null

    Union All

    Select 2, 'IT','Internal, External'

    Union All

    Select 3, 'Audit, Security', 'Internal'

    Union...

  • RE: select DISTINCT cost too high?

    ananda.murugesan (8/6/2013)


    ok.. I will update you once getting from Dev.Team for the all details..

    thanks

    ananda

    Here's a guess at the business logic:

    Where a set, partitioned on GA_Drg_NO, Rev_NO and Mark_No,

    contains at...

  • RE: select DISTINCT cost too high?

    Yes of course, but folks will need a sample data script and a decent description of what the query is supposed to do.

  • RE: Subquery returned more than 1 value error message

    declare @Locality varchar(max)

    set @Locality = 'Locality Yate'

    SELECT

    T.Locality,

    [Specialty] = GS2.CodeDescription,

    t.[Status],

    [Number] = Count(T.ClientID)

    FROM (

    SELECT

    REF.ClientID,

    REF.ReferralNumber,

    SpecialtyReferredTo,

    ServiceTeam,

    Locality = ISNULL((

    SELECT TOP 1 GS.CodeDescription

    FROM dbo.vwSGReferrals As REF2 -- You don't need this reference here;...

  • RE: Table data in tabular form

    Not many folks will want to click on the link you posted. Can you post up a picture of the desired layout instead?

  • RE: Query Challenge

    ;WITH OrderedData AS (SELECT *, seq = ROW_NUMBER() OVER(ORDER BY DateS) FROM #LOGTABLE)

    SELECT

    l.DateS,

    l.Value,

    x.GroupColumn

    FROM OrderedData l

    CROSS APPLY (

    SELECT TOP 1 GroupColumn = ROW_NUMBER() OVER(ORDER BY nr.seq)

    FROM OrderedData tr

    INNER...

  • RE: Query Challenge

    Koen Verbeeck (8/6/2013)


    The difference between the two rows in group 2 is 39 seconds.

    You'll need to establish clear rules on how to divide the groups.

    Around 20 seconds doesn't work for...

  • RE: Query Challenge

    Bala' (8/6/2013)


    ... need to group based on the time ...

    Please elaborate on your group definition, including an explanation of how group 2 is derived.

  • RE: Confused with my procedure

    Oracle765 (8/5/2013)


    is there a way around this the as the variables

    @columnname1 and @columnname2 could be named anything when they are passed in as this is selected from a dynamically imported...

  • RE: Query Help - Sum by Month

    ET DATEFORMAT MDY

    SELECT

    DateRange = RIGHT('0'+CAST(MONTH([Date]) AS VARCHAR(2)),2)+'/'+

    CAST(YEAR([Date]) AS VARCHAR(4)),

    SUMAmount = SUM(Amount)

    FROM (

    SELECT '01/03/2012', $300 UNION ALL

    SELECT '01/12/2012', $250 UNION ALL

    SELECT '02/05/2012', $200 UNION ALL

    SELECT '02/07/2012', $300 UNION ALL

    SELECT...

  • RE: Convertion from Varchar to Datetime

    SELECT CONVERT(DATETIME,RIGHT(MyDate,4)+LEFT(MyDate,4),112)

    FROM (SELECT MyDate = '12252013') d

  • RE: Are the posted questions getting worse?

    Brandie Tarvin (8/2/2013)


    How many people (besides Jeff and myself) have written SQL Spackle articles?

    How many SQL Spackle articles are there?

    Yes, I have a reason for asking. But I want to...

Viewing 15 posts - 4,216 through 4,230 (of 10,144 total)