April 24, 2011 at 7:40 am
I have a database that has a column of Text
Table
column1 (Type of Object) nvarchar(22)
column2 (Type of Error Code) nvarchar(22)
column3 (Data) text
Data consists of [Error] this is the first error [Error] this is the second
Trying to get it to return in rows
column1, column2 column3
program1, check , this is the first error
program1, check, this is the second error
Somes data is 100 characters others may have 1800 errors.
Any ideas of how to split the data out.
April 24, 2011 at 8:13 am
please provide table def and ready to use sample data in the form of INSERT ... SELECT as well as your expected result. Otherwise we just have to guess the table structure. it's possible that a pslit string function might be the solution, but that's hard to tell at the moment.
April 24, 2011 at 8:34 am
CREATE TABLE [dbo].[TABLE1](
[ID] [nvarchar](22) NOT NULL,
[CONTEXT] [nvarchar](30) NOT NULL,
[VALUE_ID] [nvarchar](22) NOT NULL,
[PROCESS_ID] [nvarchar](59) NOT NULL,
[DATA] [text] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
ID = '1'
CONTEXT = 'Project'
VALUE_ID = '1000'
PROCESS_ID = 'Check'
DATA = 'Process Name: Check User: Sor Start Time: 04/20/2011 03:51:07 PM Project: 1000 Check. [Error]CA (open) Invalid Forecast [Error]WP (open) / 10000 / Invalid Process completed. Finish time: 04/20/2011 03:51:31 PM Errors: 21 Warnings: 0'
Expected Output
CONTEXT, VALID_ID, PROCESS_ID, DATA
Project 1000 Check [Error]CA (open) Invalid Forecast
Project 1000 Check [Error]WP (open) / 10000 / Invalid '
Insert
declare @text as text
set @text = 'Process Name: Check User: Sor Start Time: 04/20/2011 03:51:07 PM Project: 1000 Check. [Error]CA (open) Invalid Forecast [Error]WP (open) / 10000 / Invalid Process completed. Finish time: 04/20/2011 03:51:31 PM Errors: 21 Warnings: 0 '
INSERT INTO TABLE1 (CONTEXT,VALUE_ID, PROCESS_ID, DATA)
SELECT 'Project','1000','Check',@text
(Insert not work said text, nxtext are invalid or local variables
Size of my datatype TEXT column is 1319433
April 24, 2011 at 10:48 am
This will get you the different errors. The issue is that the last error has additional information after the error message - you'll have to figure out how to remove that.
The latest DelimitedSplit8K function is linked to in my signature.
SELECT *
FROM #table1 t1
CROSS APPLY dbo.DelimitedSplit8K(REPLACE(CONVERT(VARCHAR(max),t1.data), '[Error]', '|'), '|') ds
WHERE ds.ItemNumber > 1
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 24, 2011 at 1:31 pm
Worked on my small sample of data, now running on my hugh output.
Thank you for your time and supplying code.
April 24, 2011 at 2:02 pm
Thanks for the feedback.
How did you handle the apparently extra stuff at the end of the last error message?
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 24, 2011 at 3:55 pm
The last part at the end wasn't of much use for the users just the Error detail so left that in there.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply