You are here: Substring and Charindex Script Not Working « MsSQL Server « IT news, forums, messages
Substring and Charindex Script Not Working

Posted by db55 on 10/02/28 11:48

This script doesn't work. Why?

UPDATE [460zz_Relma_Comment_Parse]
SET [Comments 1] = LTRIM(SUBSTRING([Comments], 1,
convert(bigint, CHARINDEX(',', Comments)-1)))
WHERE NOT([COMMENTS] IS NULL) AND LEN([Comments]) > 8

Basically, I'm trying to move everything before a comma into [Comments
1] and everything after the comma into [Comments 2]. The comments 2
script works. See below.

UPDATE [460zz_Relma_Comment_Parse]
SET [Comments 2] = LTRIM(SUBSTRING([Comments], convert(bigint,
charindex(',', [Comments])+1), Len([Comments]) - charindex(',',
[Comments])))
WHERE NOT([COMMENTS] IS NULL) AND LEN([Comments]) > 8

This script [Comments 2] runs perfectly but the first one [Comments 1]
above gives me the following error.

Msg 536, Level 16, State 5, Line 1
Invalid length parameter passed to the SUBSTRING function.
The statement has been terminated.

They are basically the same script except I'm adding +1 to one script
and minusing one -1 from the other.

Thanks,

db55

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация