Require complex data format

  • Hi,
    I need the report.Format and base data  is attached in excel  file.

    Kindly help me with desired output.

  • You should already know this, but can you please post proper sample data and DDL (see the link in my signature), and the expected output. The floats are really malformed when copying and pasting to and from Excel. Plus, most, won't open an Excel Document from a stranger. Also, some logic to how you get from your original data to the original would be great.

    Provided data we can use makes it much more likely someone is going to give you an answer to your question.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • CREATE TABLE [dbo].[test](
        [LeadId] [nvarchar](255) NULL,
        [PgNm] [nvarchar](255) NULL,
        [Start_Date] [datetime] NULL,
        [End_Date] [datetime] NULL,
        [UsrNm] [nvarchar](255) NULL
    ) ON [PRIMARY]

    INSERT INTO [dbo].[test]
        ([LeadId]
        ,[PgNm]
        ,[Start_Date]
        ,[End_Date]
        ,[UsrNm])
      VALUES
        (1 ,'Start','7/1/2017 1:17:31 PM','7/2/2017 1:17:31 PM', 'John'),
              (1 ,'Scan','7/3/2017 1:17:31 PM','7/5/2017 1:17:31 PM', 'bell'),
                 (1 ,'Quick Data Entry','7/6/2017 1:17:31 PM','7/10/2017 1:17:31 PM', 'delli'),
                 (1 ,'Quick Data Entry','7/11/2017 1:17:31 PM','7/12/2017 1:17:31 PM', 'money'),
                 (1 ,'RCU Approval','7/13/2017 1:17:31 PM','7/15/2017 1:17:31 PM', 'jimmy'),
                  (1 ,'end','7/15/2017 1:17:31 PM','7/16/2017 1:17:31 PM', 'ferry')

                    alter table [test]
                    alter column gap varchar(50)

                    update [test]
                    set gap =
    convert(varchar(10), (DateDiff(s, [Start_Date], End_Date)/86400)) + ':' +
    convert(varchar(10), ((DateDiff(s, [Start_Date], End_Date)%86400)/3600)) + ':'+
    convert(varchar(10), (((DateDiff(s, [Start_Date], End_Date)%86400)%3600)/60)) + ':'+
    convert(varchar(10), (((DateDiff(s, [Start_Date], End_Date)%86400)%3600)%60))

    /***** Desired Output ****/

     

    LeadId             Start_UsrNmStartScan_UsrNm  ScanQuick   Data En try_UsrNmQuick Data EntryRCU Approval_UsrNmRCU Approvalend_UsrNmend
    1        John1:0:0:0bell2:0:0:0delli5:0:0:0jimmy2:0:0:0ferry1:0:0:0
  • This is easy using cross tabs. Here's a snippet on how to do it, you'll need to complete it.

    SELECT LeadId,
      MAX(CASE WHEN PgNm = 'Start' THEN [UsrNm] END) AS Start_UsrNm,
      MAX(CASE WHEN PgNm = 'Start' THEN gap  END) AS Startd,
      MAX(CASE WHEN PgNm = 'Scan' THEN [UsrNm] END) AS Scan_UsrNm,
      MAX(CASE WHEN PgNm = 'Scan' THEN gap  END) AS Scan
    FROM test
    GROUP BY LeadId;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply