Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 19th, 2007, 03:20 PM
Authorized User
 
Join Date: Apr 2005
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


 
Old March 19th, 2007, 04:35 PM
Authorized User
 
Join Date: Dec 2006
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
 
Old March 19th, 2007, 07:18 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


 
Old March 20th, 2007, 02:09 AM
Friend of Wrox
 
Join Date: Jun 2003
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





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





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