473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with Updatetext in SQL 2000 trying to concatenate multiple text fields

Dan
Hi all, I am creating a search table where the keywords field is made
up of several text fields and this is causing me some problems. I can
concatentate the text ok but i can't seem to concatenate matching
records here is the cursor loop. I'm not a fan of cursors but also
didn't see another way of achieving this.

declare @ptr1 varbinary(16)
declare @Ptr2 varbinary(16)
declare @profileid int
declare @x int

set @profileid = 0

while @profileid is not null
begin

select
@profileid = min([id]),
@ptr1 = MIN(textptr(text1))
from #holding
where [id] @profileid
declare c2 cursor fast_forward for
select textptr(searchterms), datalength(searchterms)
from search
where search.[id] = @profileid

open c2

fetch c2 into @ptr2, @x

while @@fetch_status = 0
begin
updatetext search.searchterms @ptr2 null 0 #holding.text1 @ptr1
fetch c2 into @ptr2, @x
end

close c2
deallocate c2

end

The #holding table contains the fields that i want to concatenate and
the search table is the resulting table. This example would loop
through search and find id 1 in search and then append another field
matching id 1 in holding then move onto the next field in turn going
through the whole table.

i.e.

search holding result after each loop
id text id text
1 abc 1 def abcdef
2 ghi 2 jkl ghijkl
When I run this, some of the records concatenate properly but most dont
with the same text being appended to the end of searchterms. i.e loads
of results will end up with jkl tagged onto the end. I can't figure out
when my loop is falliing over!!! Can anyone help?

Dan

Jan 2 '07 #1
4 5027
Dan (da************@hotmail.com) writes:
select
@profileid = min([id]),
@ptr1 = MIN(textptr(text1))
from #holding
where [id] @profileid
This does not look good. Is there are any reason to assume that text
pointers are aligned with id?

Either do

SELECT @profileid = MIN(id)
FROM #holding
WHERE id @profileid

SELECT @ptr1 = textptr(text1) FROM #holding WHERE id = @profileid

Or run a second cursor over #holding.

And, yeah, this is ugly, painful and no fun at all. But it's the only
alternative.

In SQL 2005 there are new data types that replaces text & co, and
which does not have all the restrictions of text. Or the need to
use UPDATETEXT...
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 2 '07 #2
Dan wrote:
When I run this, some of the records concatenate properly but most dont
with the same text being appended to the end of searchterms. i.e loads
of results will end up with jkl tagged onto the end. I can't figure out
when my loop is falliing over!!! Can anyone help?
I don't know /why/ the loop is doing the wrong thing, but adding some
debugging output after the UPDATETEXT line (e.g. SELECT * FROM SEARCH)
should at least reveal /when/ it's doing the wrong thing.

Also, I would seriously avoid columns named "id".
Jan 2 '07 #3
Dan
Thanks Erland, you hit the nail on the head, i misunderstood what the
textptr did and thought both could be set at the same point. Hopefully
this will be the one and only time i have to use either text
concatenation or cursors. Is is the varchar(max) that replaces text in
SQL Server 2005?

Thanks again

Dan
Erland Sommarskog wrote:
Dan (da************@hotmail.com) writes:
select
@profileid = min([id]),
@ptr1 = MIN(textptr(text1))
from #holding
where [id] @profileid

This does not look good. Is there are any reason to assume that text
pointers are aligned with id?

Either do

SELECT @profileid = MIN(id)
FROM #holding
WHERE id @profileid

SELECT @ptr1 = textptr(text1) FROM #holding WHERE id = @profileid

Or run a second cursor over #holding.

And, yeah, this is ugly, painful and no fun at all. But it's the only
alternative.

In SQL 2005 there are new data types that replaces text & co, and
which does not have all the restrictions of text. Or the need to
use UPDATETEXT...
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 3 '07 #4
Dan (da************@hotmail.com) writes:
Is is the varchar(max) that replaces text in SQL Server 2005?
Yes.

And to make it clear, text is still there but deprecated. You will
have to make an explicit change to the tables to use the new goodies.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: James | last post by:
I am currently working on a PHP based website that needs to be able to draw from Oracle, MS SQL Server, MySQL and given time and demand other RDBMS. I took a lot of time and care creating a...
8
by: euang | last post by:
Hi, I have been using access 2000 for two years on WINDOWS NT to display dynamic aweb page using ASP My ISP has now changed to Windows 2003, and I am having major problems displaying...
4
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a form with multiple pages on it. There is one text field on the third page of the form that I need the user to complete before leaving the form or moving...
4
by: Stephen | last post by:
I have the following code working in order to create an array list and populate a datagrid however everytime i click my button the first item in the array and the first row in the datagrid are...
2
by: Iain | last post by:
Hi All Using Delphi 2006 developer - C# Project I have the following 2 event handlers for the datagrid - see botton of page Both events will fire off correctly but i have a problem collecting...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
5
by: Zamdrist | last post by:
I need to update/change the text in a table column of data type TEXT. It's a smaller set of records (72) where I need to append onto the end a string of text, the same for all records. I don't...
3
by: Artie | last post by:
I have a question on the UPDATETEXT function (SQL 2000) The below query works and only updates the record where p.pub_id = pr.pub_id. I just don't quite understand why only 1 record is updated...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.