Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 19th, 2007, 03:20 PM
Authorized User
 
Join Date: Apr 2005
Location: Vancouver, , Canada.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default parsing a string using charindex and substring

I need to parse out only the middle string from a whole string using a select statement. I'm able to accomplish this in a loop only after I've selected the whole string. However, it doesn't serve my purpose to do it this way.



here's the code that I need to be in a select

set @shortcellname = substring(@description,len(SUBSTRING(@description, 1, CHARINDEX('_',@description)) )+1,len(SUBSTRING(@description, 1, CHARINDEX('.',@description)) )-len(SUBSTRING(@description, 1, CHARINDEX('_',@description)) ))
  set @shortcellname = substring(@shortcellname, 1, charindex('_',@shortcellname)-1)
  set @shortcellname = replace(@shortcellname, ' ',' ')

the first set works fine - I'm having a problem combining the 1 and 2nd sets into the following:

substring(substring(description,len(SUBSTRING(desc ription, 1, CHARINDEX('_',description)) )+1,len(SUBSTRING(description, 1, CHARINDEX('.',description)) )-len(SUBSTRING(description, 1, CHARINDEX('_',description)) )),1, charindex('_',(substring(description,len(SUBSTRING (description, 1, CHARINDEX('_',description)) )+1,len(SUBSTRING(description, 1, CHARINDEX('.',description)) )-len(SUBSTRING(description, 1, CHARINDEX('_',description)) )))-1))



I get the following error:

Syntax error converting the nvarchar value 'sample string from description column.' to a column of data type int.



anyone what to attempt this resolution


Reply With Quote
  #2 (permalink)  
Old March 19th, 2007, 04:35 PM
Authorized User
 
Join Date: Dec 2006
Location: Lake Wylie, SC, USA.
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried to make sense of what you are trying to accomplish.
The first sql statement does not work.
When using 'sample string from description column.' for @description.
Msg 536, Level 16, State 5, Line 16
Invalid length parameter passed to the SUBSTRING function.

Can you explain a little more about what you are trying to accomplish?

Adam Gossage
Lake Wylie, SC, USA
Reply With Quote
  #3 (permalink)  
Old March 19th, 2007, 07:18 PM
Friend of Wrox
 
Join Date: May 2006
Location: Helsingborg, , Sweden.
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this function
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


Reply With Quote
  #4 (permalink)  
Old March 20th, 2007, 02:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Cole,

Can you post it explaining what you are trying to do with some example string value, mentioning the whole process of you accomplisment? So that it is easy for one to understand, than going through a lot of substring and charindex which will end up getting too complicated for one to look into.

cheers.

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing from a text string jroxit Classic ASP Basics 5 November 18th, 2008 05:08 PM
Parsing of String jmss66 VB How-To 9 May 1st, 2008 12:47 AM
Parsing a String? MBowen SQL Server 2000 9 December 1st, 2006 01:17 PM
Parsing string to check for substring bcamp1973 XSLT 2 June 5th, 2006 06:44 PM
How to extract a substring from a string.... muralish MySQL 2 May 18th, 2005 06:58 AM



All times are GMT -4. The time now is 02:54 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.