Forum Replies Created

Viewing 15 posts - 31 through 45 (of 58 total)

  • Reply To: LAST MAX 2 DATES

     

    Here is required  output

    ('577', '-1','1','2021-02-14');

    ('563', '-1','1','2021-02-13')

  • Reply To: LAST MAX 2 DATES

    or please share me any other query which will show  max of last 2 days

  • Reply To: LAST MAX 2 DATES

    here is the query

     

    SELECT Div_ID,

    CustomerID,

    Div_Status,

    LogDate ,

    LogDate

    FROM ( SELECT Div_ID,

    CustomerID,

    Div_Status,

    LogDate,

    LAG(Div_Status,1,0) OVER (PARTITION BY Div_ID ORDER BY logdate) AS PreviousValue,

    LEAD (Div_Status,0,1) OVER (PARTITION BY Div_ID ORDER BY logdate) as NextValue

    FROM dbo.Table_1

    ) AS...

  • Reply To: LAST MAX 2 DATES

    can not select top2 logdate along with other columns when really not required

  • Reply To: LAST MAX 2 DATES

    Please do not use top(2) . i can not use in my existing query ..help me with alternatives

  • Reply To: LAST MAX 2 DATES

     

    Sorry, here is input  data for last 2 max days

    INSERT INTO [dbo].[Table_1]

    ([div_id]

    ,[customerid]

    ,[div_status]

    ,[logdate])

    VALUES

    ('563', '-1','1','2021-02-13'),

    ('577', '-1','1','2021-02-12'),

    ('577', '-1','1','2021-02-10');

  • Reply To: lead and lag records

    Suggestion please

  • Reply To: lead and lag records

    sorry  -1 mistakenly came. it is 1 only in the first row

  • Reply To: lead and lag records

    Actually more data loaded.. So instead of 1,01,0 records more 1,1,1 values coming div_status

     

     

  • Reply To: lead and lag records

    output is getting more 1,1,1 records 1,0,1,0..Any suggestion...

  • Reply To: lead and lag records

     

    Hi Expert,




    here is the query

    Create table statement

    CREATE TABLE [dbo].[Table_1](
    [div_id] [nchar](10) NULL,
    [customerid] [nchar](10) NULL,
    [div_status] [nchar](10) NULL,
    [logdate] [date] NULL
    ) ON [PRIMARY]
    GO




    Insert Data:

    INSERT INTO [dbo].[Table_1]
    ([div_id]
    ,[customerid]
    ,[div_status]
    ,[logdate])
    VALUES
    ('495','-1','-1','2021-02-14'),

    ('495','-1' ,'1','2021-02-14'),
    ('495','-1' ,'1','2021-02-14'),
    ('502' ,'-1', '1','2021-02-14'),
    ('513', '-1','1','2021-02-14'),
    ('538', '-1','1','2021-02-14'),
    ('545', '-1','1','2021-02-14'),
    ('563', '-1','1','2021-02-14'),
    ('577',...
  • Reply To: lead and lag records

    Attached excel sheet

    Attachments:
    You must be logged in to view attached files.
  • Reply To: lead and lag records

    Hi Expert,

     

    I pump more data and tried to get values 1,0(active and inactive) order by logdate but even changing in queries not getting proper values for whole table. Sample data...

  • Reply To: lead and lag records

    Table is attached in excel sheet due to format issue

    Attachments:
    You must be logged in to view attached files.
  • Reply To: Sql Server Migration

    Suggestion please

Viewing 15 posts - 31 through 45 (of 58 total)