Solved

Substring or Charindex?

Posted on 2009-05-11
5
511 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 5 115
Access Date Query 28 29
Access recordset not updateable 8 38
BULK INSERT most recent CSV 19 19
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now