Solved

Substring or Charindex?

Posted on 2009-05-11
5
514 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:N R
5 Comments
 
LVL 6

Expert Comment

by:bull_rider
ID: 24358128
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.
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 24358133
select substring(col_name, 12, charindex(';') - 12 )
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24358138
this should do:
select substring( left(yourfield, charindex(';', yourfield)-1), charindex(' ', yourfield)+1, 100)

Open in new window

0
 
LVL 6

Expert Comment

by:bokist
ID: 24358159
Try this way

select ltrim(rtrim(substring(invoiceNo, charindex(':', invoiceNo) +1, charindex(';', InvoiceNo) -1)))
0
 
LVL 6

Expert Comment

by:bokist
ID: 24358261
Little bit too late, now I learned to refresh allways before posting
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question