This script doesn't work. Why?
UPDATE [460zz_Relma_Com ment_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_Com ment_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 1 3692
db55,
You probably have rows where there is a Comment (of at least 8
characters) that has no ',' in it, as in the following example:
SELECT LTRIM(SUBSTRING (Comments, 1, convert(bigint, CHARINDEX(',',
Comments)-1)))
FROM (
SELECT 'this is just an example' AS Comments
) AS "460zz_Relma_Co mment_Parse"
WHERE NOT(COMMENTS IS NULL) AND LEN(Comments) > 8
-- AND Comments LIKE '%,%'
Server: Msg 536, Level 16, State 3, Line 1
Invalid length parameter passed to the substring function.
HTH,
Gert-Jan
db55 wrote: This script doesn't work. Why?
UPDATE [460zz_Relma_Com ment_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_Com ment_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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robin Tucker |
last post by:
My code prints out 0 for the value of charindex ( 'Hello.', '.' ).
Did I miss something? I think it should print out 6!
|
by: M Wells |
last post by:
Hi All,
Just wondering if it's any more efficient to use the following SQL
statement to return a partial match from a column as opposed to the
second statement.
SELECT * FROM Table1 WHERE CHARINDEX('value', mycol) > 0
Versus:
|
by: sysindex |
last post by:
I am trying to find a way to dynamically retrieve the substring
starting point of an nText field.
My query looks something like
SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT like
'claim%'"
This query has substring starting point set to 0. Is there a way to
determine the starting point based on the first occurrence of the
|
by: Little PussyCat |
last post by:
Hello,
I need to be able to replace only the first occurance of a space character
in a column.
Reason being is the data in the column I am trying to replace seems to have
umpteen space characters after each entry, so a simple replace function
will replace all the spaces after it with what I want!
I have thought of RTRIM to get rid of the spaces after and then replace, I
have also thought of CHARINDEX to find the first occurance of a...
|
by: Tim Soliday |
last post by:
I have been looking at regular expressions lately, and I'm hoping that
maybe someone could help me?
I am trying to find the position of a substring, and then returning the
substring including any information that I might want whether it is to the
left or right of that substring.
For example:
//Position of substring has already been determined
| |
by: Daviso |
last post by:
Hi.
I hava an input like this
<td><input name=numberA> </td>
and a button with a javascript function in onclick event.
I want to control that the first element of the value I have introduced in
numberA will be different and make a conditional
|
by: chudson007 |
last post by:
I need help capturing information from a free text field.
The 10 examples below contain examples of the information I am trying
to capture.
In each cell I am trying to capture the number between 'TranID=' and
the next '&'.
So in the fisrt cell I would like to capture 14078800.
Things you will need to keep in mind are;
The number is not of fixed length.
|
by: jknaty |
last post by:
I'm trying to create a function that splits up a column by spaces, and
I thought creating a function that finds the spaces with CHARINDEX and
then SUBSTRING on those values would an approach. I get an error
saying that the I have an Invalid column 'Course_Number'. Not sure
why but I am very new to User Defined Functions. Here is what I have
so far:
CREATE FUNCTION CourseEvalBreakdown
(
|
by: jeremy |
last post by:
Hello,
I was hoping someone could help me with this SQL statement.
The column 'options.optionDescrip' is a varchar field.
Some values of the 'options.optionDescrip' contain commas, some do
not.
We are trying to evaluate against any data in the
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |