Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
danyeung
Posting Yak Master
102 Posts |
Posted - 2007-10-31 : 12:39:49
|
| I tried this and worked. It printed out 'somewhere'declare @str as char(20)set @str = 'region - somewhere'print substring(@str, 10, len(@str) - 9)Why I used the same syntax in a where clause and it didn't work? I got an error "Invalid length parameter passed to the SUBSTRING function."WHERE substring(nvchrName, 10, LEN(nvchrName) - 9) = nvchrRegionThanks.DanYeung |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-10-31 : 12:44:14
|
your string in nvchrName is less than 10 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
danyeung
Posting Yak Master
102 Posts |
Posted - 2007-10-31 : 13:40:04
|
| You are right. Thanks.DanYeung |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-10-31 : 13:42:03
|
| len excludes the space charaters at the end of the string. Substring errors if there is a length less than zeo.The error you are gettnig means there is at least one row in the table with that column too short for the substring.why notWHERE substring(nvchrName, 10, 1000) = nvchrRegion==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-01 : 02:34:35
|
| ornvchrName like '%'+nvchrRegion??MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|