• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 527
  • Last Modified:

Substring or Charindex?

I'm trying to only pull the Invoice Number from this data:

InvoiceNo: 14307; Total Amount: $11.72
InvoiceNo: 10444; Total Amount: $40.91
InvoiceNo: 12281; Total Amount: $40.91
InvoiceNo: 8705; Total Amount: $40.91
InvoiceNo: 11503; Total Amount: $35.16
InvoiceNo: 10232; Total Amount: $75.83
InvoiceNo: 12609; Total Amount: $40.91
InvoiceNo: 13401; Total Amount: $15.00
InvoiceNo: 5991; Total Amount: $22.34
Nathan Riley
Nathan Riley
1 Solution
I would say SUBSTRING as well as CHARINDEX to get the invoice value. CHARINDEX to gethe index of the semicolon and substrng to retrieve all characters from 12th position to the charindex of the semicolon.
select substring(col_name, 12, charindex(';') - 12 )
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this should do:
select substring( left(yourfield, charindex(';', yourfield)-1), charindex(' ', yourfield)+1, 100)

Open in new window

Try this way

select ltrim(rtrim(substring(invoiceNo, charindex(':', invoiceNo) +1, charindex(';', InvoiceNo) -1)))
Little bit too late, now I learned to refresh allways before posting
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now