Cursor and Proceudre

Last Post 18 May 2008 02:24 PM by SQLUSA. 3 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
snow12
New Member
New Member

--
18 May 2008 11:39 AM
Hello:

I want to find that the ntext column data string have more than 2000 characters. I need to truncate those strings to the segments with 200 character, then put those segments along with their table_name and column_name to another table. Maybe need to use cursor? If so, how to use it?

Your help is highly appreciated.

S
SQLUSA
New Member
New Member

--
18 May 2008 02:24 PM
This is how you do a cursor:
USE AdventureWorks;
DECLARE @Vendor varchar(50)
DECLARE curVendor CURSOR
FOR SELECT Name FROM Purchasing.Vendor
OPEN curVendor
FETCH NEXT FROM curVendor INTO @Vendor
WHILE @@FETCH_STATUS = 0
BEGIN

--*****PUT YOUR LOGIC HERE



FETCH NEXT FROM curVendor INTO @Vendor
END

You can just do a WHILE loop also without cursor, pretty much the same.

The READTEXT function reads an ntext column. See BOL for usage.

Kalman Toth - Database, Data Warehouse & Business Intelligence Architect
SQL Server Training, SSAS, SSIS, SSRS: http://www.sqlusa.com/
snow12
New Member
New Member

--
18 May 2008 09:32 PM
Hello:

Thanks for the reply. Actually problem is ntext hold > 4000 char. I need to split ntext data into the segnments with 4000 char. Then put those segnments to the another table. For example: The ntext data string has 12000 char. The another table has the char field. The column has segnment1(4000 char), segnment2(4000 char), segnment 3(4000 char) which come from the splitting ntext data sting with 12000 char.

I declare the cursor, but I got the error: The text, ntext, and image data types are invalid for local variables.


How to make it work?

Thanks for the help.
SQLUSA
New Member
New Member

--
19 May 2008 09:44 AM
Post removed
You are not authorized to post a reply.

Acceptable Use Policy