SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Split a Record using Substring


Split a Record using Substring

Author
Message
mk.kamalanand
mk.kamalanand
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 7
Hi All,

I have records stored in a table in below formats . Want the result in an arranged format as shown below. I tried with substring but not get it as required. Can anyone help to get it done.

Description
------------------------------------------------------------------------------------------------------------------------------------------------
String '33417' does not match regex pattern '^[0-9]{5}([ -]?)[0-9]{4}$'. Path 'Draft1[38]['Emp Code']', line 638, position 125.
Invalid type. Expected String, Numbers have Null. Path 'Draft1[1].DOB', line 131, position 11.
String ' ' does not validate against format 'date-time'. Path 'Draft1[40]['Hire Date']', line 47, position 5.
Invalid type. Expected String, Number Null. Path 'Draft1[124].DOB', line 1004, position 179.
String '69316' does not match regex pattern '^[0-9]{4}([ -]?)[0-9]{4}$'. Path 'Draft1[13]['Emp Name']', line 1364, position 215.

Result should be like

Description
------------------------------------------------------------------------------------------------------------------------------------------------
In Document 'Draft1 - Column['Emp Code'] - Row Number[38]'. --> String '33417' does not match regex pattern '^[0-9]{5}([ -]?)[0-9]{4}$'.
In Document 'Draft1 - Column.DOB - Row Number[1]'. --> Invalid type. Expected String, Numbers have Null.
In Document 'Draft1 - Column['Hire Date'] - Row Number[40]'. --> String ' ' does not validate against format 'date-time'.
In Document 'Draft1 - Column.DOB - Row Number[124]'. --> Invalid type. Expected String, Number Null.
In Document 'Draft1 - Column['Emp Name'] - Row Number[13]'. --> String '69316' does not match regex pattern '^[0-9]{4}([ -]?)[0-9]{4}$'.



Thanks,
Anand
Thom A
Thom A
SSC-Forever
SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)

Group: General Forum Members
Points: 46222 Visits: 15719
I'm honestly not sure SQL Server is the correct answer to doing this. This is going to take A LOT more than a SUBSTRING. Especially if that error is stored in a single column.


Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does :-P

Please always remember to encapsulate your code in IFCode Markup. For example [code=sql] [/code].
Click here to read Jeffs Guide on how to post SQL questions, and get swift and helpful answers from the community
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (512K reputation)SSC Guru (512K reputation)SSC Guru (512K reputation)SSC Guru (512K reputation)SSC Guru (512K reputation)SSC Guru (512K reputation)SSC Guru (512K reputation)SSC Guru (512K reputation)

Group: General Forum Members
Points: 512825 Visits: 44328
mk.kamalanand - Friday, December 22, 2017 1:53 AM
Hi All,

I have records stored in a table in below formats . Want the result in an arranged format as shown below. I tried with substring but not get it as required. Can anyone help to get it done.

Description
------------------------------------------------------------------------------------------------------------------------------------------------
String '33417' does not match regex pattern '^[0-9]{5}([ -]?)[0-9]{4}$'. Path 'Draft1[38]['Emp Code']', line 638, position 125.
Invalid type. Expected String, Numbers have Null. Path 'Draft1[1].DOB', line 131, position 11.
String ' ' does not validate against format 'date-time'. Path 'Draft1[40]['Hire Date']', line 47, position 5.
Invalid type. Expected String, Number Null. Path 'Draft1[124].DOB', line 1004, position 179.
String '69316' does not match regex pattern '^[0-9]{4}([ -]?)[0-9]{4}$'. Path 'Draft1[13]['Emp Name']', line 1364, position 215.

Result should be like

Description
------------------------------------------------------------------------------------------------------------------------------------------------
In Document 'Draft1 - Column['Emp Code'] - Row Number[38]'. --> String '33417' does not match regex pattern '^[0-9]{5}([ -]?)[0-9]{4}$'.
In Document 'Draft1 - Column.DOB - Row Number[1]'. --> Invalid type. Expected String, Numbers have Null.
In Document 'Draft1 - Column['Hire Date'] - Row Number[40]'. --> String ' ' does not validate against format 'date-time'.
In Document 'Draft1 - Column.DOB - Row Number[124]'. --> Invalid type. Expected String, Number Null.
In Document 'Draft1 - Column['Emp Name'] - Row Number[13]'. --> String '69316' does not match regex pattern '^[0-9]{4}([ -]?)[0-9]{4}$'.



Thanks,
Anand


Help us help you. See the first link under "Helpful Links" in my signature for how to post readily consumable data and post your code so we can try to figure out what you're really trying to do. It looks like you may have a pretty decent data validation system/bulk log staging table setup but it's difficult to advise you how to format your "validation failed" messages without you posting your code.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search