sql server - Combining values of a specific column from consecutive rows in SQL -


I am exporting my logs to SQL. The problem is that the logging API trims the message column if this length is 800.

Exceeds characters and creates new entries with the rest of the message. I use loggers to export this data directly to SQL. Therefore, for the rest of the discussion, suppose I have to solve this problem in SQL.

The SQL table looks like this

  id timestamp eventad message 1 2014-04-23 ABCD "some messages"   

if If the number of characters in the message is greater than 800, then we will have a new line in the table, with the message starting with "...", the original line will end with "..." according to the next things. .

For example

  ID Timestamp event ADI message 1 2014-04-23 ABCD "Some messages ..." 2 2014-04-23 abcd "... More messages ... "3 2014-04-23 ABCD" ... even more messages "  

Note that the IDs are consistently of the associated message. And nothing is guaranteed that the timestamp is guaranteed to be the same for a split, but there is no different meaning that the other entries in the table can be with the same timestamp. It goes the same for eventID .

Problem
Looking at this data in the table, I want to create a scene that connects messages in a similar manner, so a single unified message Never be aware of trimming behind the scenes.

The result should look like this

  ID timestamp eventad message 1 2014-04-23 abcd "Some messages more messages and even messages" < / Code>   

First of all examine the length of the column in the 'Message' column in your table.

In my opinion, you can get it in any of the two options.

Option 1: Run a SQL script every day, which will create a single entry by adding all the messages in the 'Message' column to a specific timestamp; EventID

(I am assuming SQL Server, but I am sure that there is something similar in other RDBMS)

  Timestamp, EventID, select Combined Message (Message of Select + '' FROM table T2 where the XML path ('') for t2.Timestamp = t1.Timestamp and t2.EventID = t1.EventID), 1,1, '') [NewTable] group timestamp from table ten By, EventEdent Code here   

Yes, I am suggesting to create a new table in which your desired data is also in the evening Option 2: At my workplace, I wrote an app in C # that will load the web logs in the data test every night using the log parser and then the table But our project will do specific post processing on imported data. Similarly, after importing your data into the table, you can create a simple console app that will do the following:

Use the following query to create a data set,

  

Now in your app, the SELECT t.Timestamp, t.EventID, t.Message, ROW_NUMBER () by (via T. Temstamp by T.EventID order) section.

  [Data Set] {1 for each line number} Insert message 2. Enter the combined message record in your original table 3. Calculate the maximum (LAN) and delete all the other entries which are less than the message MAX (message). Now you have a certain timestamp, EventID And are left with only one entry for the amp; Message}   

Hope that the above information will help.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -