Import TEXT to TABLE in MSSQL

By: Fernando Emailed: 1603 times Printed: 2076 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Use this code to import value in text into a table in MSSQL

CREATE PROCEDURE dbo.EachLineToTable --'String1,String2,String3,String4,MyNameIs,TestDriveFromBIGString,GOGOGO,Bye'
@Text TEXT
AS
DECLARE @StrLine VARCHAR(8000)
DECLARE @Size BIGINT
DECLARE @Start BIGINT
DECLARE @Separator VARCHAR(1)
DECLARE @TempImport TABLE(Idx BIGINT IDENTITY(1,1), SplitedLine VARCHAR(8000), Size INT)

SET @Size = 1
SET @Start = 1
SET @Separator = ','

WHILE (@Start < DATALENGTH(@Text) + 1) BEGIN
SET @Size = CHARINDEX(@Separator, SUBSTRING(@Text, @Start, DATALENGTH(@Text)), 1)
IF @Size = 0 SET @Size = DATALENGTH(@Text) - @Start + 1
SET @StrLine = SUBSTRING(SUBSTRING(@Text, @Start, DATALENGTH(@Text)), 1, @Size)
SET @StrLine = REPLACE(@StrLine,@Separator,'')
INSERT INTO @TempImport(SplitedLine, Size) VALUES(@StrLine, LEN(@StrLine))
SET @Start = @Start + @Size
END

SELECT * FROM @TempImport

JDBC Home | All JDBC Tutorials | Latest JDBC Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Fernando
Setting up PHP in Windows 2003 Server IIS7, and WinXP 64
Import TEXT to TABLE in MSSQL

More Tutorials in JDBC
TEXT datatype SPLIT in MSSQL - to solve the 8000 limit set by varchar
Import TEXT to TABLE in MSSQL
What is Referential Integrity in databases?
Handling CSV in Stored Procedures
setSavepoint and releaseSavepoint Example in Java
Calling a Stored Procedure from JDBC in Java
java.lang.NoClassDefFoundError and java.lang.NoSuchMethodError
Creating Database Connection Pool in Tomcat 5.0 and Tomcat 5.5 for MySQL and Java
JDBC Basics and JDBC Components
SELECT Statements
WHERE Clauses in SQL
Joins example in SQL
Common SQL Commands
Result Sets, Cursors and Transactions in SQL
Stored Procedures example in SQL

More Latest News
Most Viewed Articles (in JDBC )
A simple JDBC application sample code
How connection pooling works in Java and JDBC
Using JDBC to connect to MySQL from Java Program
JDBC Components
JDBC Architecture
What is JDBC?
Using JDBC to extract data from a database and output to an XML document
PreparedStatement Example in Java
setSavepoint and releaseSavepoint Example in Java
Import TEXT to TABLE in MSSQL
The Structure of JDBC
What is the ACID principal?
Using Transactions in JDBC
Data Access Technologies in Java
JDBC and Tomcat context settings
Most Emailed Articles (in JDBC)
How connection pooling works in Java and JDBC
Using the DriverManager Class vs Using a DataSource Object for a connection
What is the ACID principal?
Common SQL Commands
Data Access Technologies in Java
Creating Database Connection Pool in Tomcat 5.0 and Tomcat 5.5 for MySQL and Java
WHERE Clauses in SQL
Result Sets, Cursors and Transactions in SQL
Stored Procedures example in SQL
Creating Database Tables Using ANT
setSavepoint and releaseSavepoint Example in Java
What is Referential Integrity in databases?
What is JDBC?
Using JDBC to extract data from a database and output to an XML document
java.lang.NoClassDefFoundError and java.lang.NoSuchMethodError