Problem With Updatetext In SQL 2000 Trying To Concatenate Multiple Text Fields
Jan 2, 2007
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?
New to using MS SQL server! I have a requirements DB. Before I came on board, the DB was seeded with requirements text and a requirements ID in separate columns. I've been asked to append the ID in front of the text:
Text - The user shall be able.... ID - 1.01.01. Combined - 1.01.01.The user shall be able....
I've created the following query that displays the columns:
CREATE VIEW dbo.ReqID AS SELECT RQREQUIREMENTS.ID, RQREQUIREMENTS.REQUIREMENTNAME, RQUSERDEFINEDFIELDVALUES.FIELDVALUE
FROM RQREQUIREMENTS LEFT OUTER JOIN RQUSERDEFINEDFIELDVALUES ON RQREQUIREMENTS.ID = RQUSERDEFINEDFIELDVALUES.REQUIREMENTID
WHERE (RQUSERDEFINEDFIELDVALUES.FIELDID = 171)
The Text field is REQUIREMENTNAME The ReqId is FIELDVALUE
Should I create an UPDATE query based on this SELECT, updating the REQUIREMENTNAME column with FIELDVALUE + REQUIREMENTNAME?
I have a table where I need to concatenate all values into one field separated by a comma. If the field is null display a blank value. This is my table structure and example output
Create Table #read ( id int ,field1 varchar(100) ,field2 varchar(100) ,field3 varchar(100) ,field4 varchar(100)
Hi, i'm trying to do a full text search on my site to add a weighting score to my results. I have the following database structure: Documents: - DocumentID (int, PK) - Title (varchar) - Content (text) - CategoryID (int, FK) Categories: - CategoryID (int, PK) - CategoryName (varchar) I need to create a full text index which searches the Title, Content and CategoryName fields. I figured since i needed to search the CategoryName field i would create an indexed view. I tried to execute the following query: CREATE VIEW vw_DocumentsWITH SCHEMABINDING ASSELECT dbo.Documents.DocumentID, dbo.Documents.Title, dbo.Documents.[Content], dbo.Documents.CategoryID, dbo.Categories.CategoryNameFROM dbo.Categories INNER JOIN dbo.Documents ON dbo.Categories.CategoryID = dbo.Documents.CategoryID GOCREATE UNIQUE CLUSTERED INDEX vw_DocumentsIndexON vw_Documents(DocumentID) But this gave me the error: Cannot create index on view 'dbname.dbo.vw_Documents'. It contains text, ntext, image or xml columns. I tried converting the Content to a varchar(max) within my view but it still didn't like. Appreciate if someone can tell me how this can be done as surely what i'm trying to do is not ground breaking.
Is there any way of concatenating 2 fields and a seperator, an id (integer) then "|||" then a nvarchar field, it would make my life much easier if I could come up with SQL that works in ms access as well as sql server.. Thanks
I have a hierarchy of product categories and I want to string them together to show the complete path (breadcrumbs) to the item. Each category/subcat must be separated buy a comma. The catch is that not all items have the same number of cats/subcats. Here is what I am currently doing, but as you can see, this results in extra commas where the subcats are null.
Hello,I'm wondering if there is a way to concatenate two fields or a field and astring value in a single field in a view?Where in Access I might write;[field1] & " (m3)" as TotalVolumeis there a way to do this in an SQL Server View?Thanks!
Does anyone have code example on how to concatenate fields in a SQL Server stored procedure? I would like to create a stored procedure to concat (off_name ' ' off_fname ' ' off_prior) to a field to bound to a combobox. Thanks, Ron
I concatenate multiple rows from one table in multiple columns like this:
--Create Table CREATE TABLE [Person].[Person_1]( [BusinessEntityID] [int] NOT NULL, [PersonType] [nchar](2) NOT NULL, [FirstName] [varchar](100) NOT NULL, CONSTRAINT [PK_Person_BusinessEntityID_1] PRIMARY KEY CLUSTERED
[Code] ....
This works very well, but I want to concatenate more rows with different [PersonType]-Values in different columns and I don't like the overhead, of using the same table in every subquery ([Person_1]). Is there a more elegant way to do this, without using a temp table or something else?
hi friends, i need the steps for full text search with more than one tables in single database. I know the steps for full text search by single table in single database. Thanks in advance
I would like to concatenate text datatypes. Is this possible?? I'm using field1 + " " + field2 I cannot convert to varchar since the size is larger than 8000.
The following sql statement fails:SELECT IdFlight, OrganizerLastName + ", " + OrganizerFirstName + "Flt:" + FlightNumber As Concat FROM TableFlights Order ByOrganizerLastName, OrganizerFirstNameI'm trying to concatenate fields and words, but my asp.net page givesme an error saying " Flt:" is not a field.Thanks,Marvin
Newbie question here. I have two tables that have a one to many relationship. I want to create a query that takes the info from the child table (possibly multiple rows) and concatenates it into a single column in the parent table. The tables are:TableParent (ASSIGNNUM (PK), DESC, STARTDATE)TableChild (ASSIGNNUM (FK), EMPLOYEENUM)There could be multiple employees for each assignment. Sample data:TableParent1....First Assignment....05/01/20082....Second Assignment...05/03/20083....Third Assignment....05/07/2008TableChild1....553422....334562....523433....352253....451213....11553I would like the query result to look like this:1....First Assignment....05/01/2008....553422....Second Assignment...05/03/2008....33456,523433....Third Assignment....05/07/2008....35225,45121,11553Any suggestions would be appreciated!
I have a SQL statement that fetches book information via a TITLE_ID which is fine if we only have one edition (hardback), but if there are two editions (hardback and paperback) it will return two rows like:
Title - Author - Edition The Amazing Pixies - A. N. Author - Hdbk The Amazing Pixies - A. N. Author - Pbk
Is there any way to concatenate the Edition field so the two lines become one? I have searched for ways to do this but have had no luck.
Someone please help!. I am trying to create a view in SQL Server 2000 to use for a report but I am having problems with concatenating multiple values into one field. In my example below I am trying to list all records in my queried table in columnA then concatenate a list of all other records that share the same value in column B of the queried table into another field. If there are no other matches for a row in columnA then I would leave the corresponding field in columnB blank. Thanks in advance.
Newbie question here. I have two tables that have a one to many relationship. I want to create a query that takes the info from the child table (possibly multiple rows) and concatenates it into a single column in the parent table. The tables are:
Hi,I hope someone here can help me.We have a product table which has a many-to-many relationto a category table (joined through a third "ProductCategory" table):[product] ---< [productCategory] >--- [category]--------- ---------------- ----------productID productCategoryID categoryIDproductName productID categoryNamecategoryIDWe want to get a view where each product occupies just one row, andany multiple category values are combined into a single value, eg(concatenating with commas):Product Category-------------------cheese dairycheese solidmilk dairymilk liquidbeer liquidwill become:Product Category-------------------cheese dairy, solidmilk dairy, liquidbeer liquidWhat is the best way to do it in SQL?Thanks and regards,Dmitri
I am using MS SQL 2012. I have a table that contains all the data that I need, but I need to summarize the data and also add up decimal fields while at it. Then I need a total of those added decimal fields. My data is like this:
I have Providers, a unique ID that Providers will have multiples of, and then decimal fields. Here are my fields:
I have followed many tutorials on selecting and replacing text in text fields, varchar fields and char fields, but I have yet to find a single script that will to all 3 based on field type. Let's assume for a moment that I don't know where all in my database a certain value that I need changed resides ... i.e., the data's tablename and fieldname. How would I go about doing the following ... or more importantly, is this even possible in a SQL only procedure?1) Loop over entire database and get all user tables2) Loop over all user tables and get all fields3) Loop over all fields and determine the field type4) switch between field types and change a string of text from 'a' to 'b'Please be gentle, I'm a procedure newb.
I have a data table in my project that has a "text" (not varchar) field in it. I am trying to load this field with little paragraphs of text for showing on my pages. How do I get the free text loaded into the table? The database explorer and all the data grid controls cut the text off at one line. There doesn't seem to be any way to get multiline text into this table.
Help, I am trying to update 1000 rows. They have the wrong extension of an image file and I'd like to change the extension only. I have tried using the following code
declare @ptrval binary(16) select @ptrval = textptr(images) from copyimages where images like '%.jpgg%' updatetext copyimages.images @ptrval 8 5 with log '.jpg' go
This works but it only updated one record. I would like it to update all the records. I have tried using a counter with nocount on but I am getting an error. Can anyone please tell me how to go about that??
Also how would I go about it if the image names were not the same length?
I would appreciate any help I can get. Thank you JG
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 enda string of text, the same for all records.I don't quite understand how UPDATETEXT and WRITETEXT work, but hereis how I would write the Update query were the field not a TEXT type.Update Matters Set Description = Description + ' (Stylized)'
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 when theUPDATETEXT statementdoes not specify anything except pointer value. Is it no possible for 2rows in a table with a text column to have the same pointer value?Does this query scan all pr_info in the pub_info table?USE pubsGOEXEC sp_dboption 'pubs', 'select into/bulkcopy', 'true'GODECLARE @ptrval binary(16)SELECT @ptrval = TEXTPTR(pr_info)FROM pub_info pr, publishers pWHERE p.pub_id = pr.pub_idAND p.pub_name = 'New Moon Books'UPDATETEXT pub_info.pr_info @ptrval 88 1 'b'GOEXEC sp_dboption 'pubs', 'select into/bulkcopy', 'false'GOAlso, what is the importance of 'select into/bulkcopy', 'true' ?Thanks
hello,i would like to update a column called footer in a table calledagency. i have to update about 60 different records in this table.footer is varchar(200)i would like to search for "<table bgcolor="#cccccc"" and replace itwith "<table "there is stuff before and after the start of the table tag.i looked at the books online and could not get the syntax correct.am i using the right command? updatetext, or should i do this with aloop?thanks in advance.nicholas.gadacz
I'm trying to run the following SQL against my column, Testtbl.Task
I want to replace where the ampersand sign got HTML encoded to "&", and I want to strip it down to only the ampersand sign and delete the "amp" and the ";", that's why my parameters for the UpdateText are 0 and 8 with no update text value.
It executes, but I still have the HTML encoding for the ampersand sign.
USE WI GO EXEC sp_dboption 'WI', 'select into/bulkcopy', 'true' GO DECLARE @ptrval binary(16) SELECT @ptrval = TEXTPTR(Task) FROM Testtbl WHERE Task like '%amp;%' UPDATETEXT Testtbl.Task @ptrval 0 8 GO EXEC sp_dboption 'WI', 'select into/bulkcopy', 'false' GO