Solved

Load file into SqlString variable using only TSQL.

Posted on 2014-02-28
5
71 Views
Last Modified: 2016-06-03
Hi,

Does anyone know if it is possible to load a file from the file system hosting an sql express instance (so no SSIS) into a SqlString using only TSQL without using xp_cmdshell or OPENROWSET(BULK.

Also CRL Integration is disabled.

Mission Impossible?

Paul Cookson
0
Comment
Question by:pncookson
5 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 39894428
you can try this option Getting Text into a Table

DECLARE @LotsOfText NVARCHAR(MAX),
       @ii INT,
       @iiMax INT,
       @File VARCHAR(2000)
DECLARE @files TABLE (MyID INT IDENTITY(1,1) PRIMARY KEY, [Path] VARCHAR(2000))
DECLARE @lines TABLE (MyID INT IDENTITY(1,1) PRIMARY KEY, [line] NVARCHAR(MAX))

DECLARE @FileList XML
EXECUTE ListPathsXML 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG.*',
    DEFAULT , @XMLFileList = @FileList OUTPUT

INSERT INTO @files(path)
   SELECT   x.thefile.value('fullpath[1]', 'varchar(2000)') AS [path]
        FROM    @FileList.nodes('//thefiles/thefile') AS x ( thefile )
DELETE FROM @files WHERE REVERSE(path) LIKE 'golrorre%'
--don't look at the current errorlog!
SELECT @ii=1, @iiMax=MAX(MyID) FROM @Files
WHILE @ii<=@iiMax
   BEGIN
   SELECT @File= [path] FROM @files WHERE MyID=@ii
   INSERT INTO @lines(line)
       EXECUTE spLoadTextFromAFile @file, @Unicode=1
   SELECT @ii=@ii+1
   END
SELECT MyID AS [line Number], Line, @file FROM @lines
       WHERE line LIKE '%Error%' 

Open in new window


refer for more deatils , this will contain all options
https://www.simple-talk.com/sql/t-sql-programming/the-tsql-of-text-files/
0
 

Author Comment

by:pncookson
ID: 39958717
Thanks Pratima, sorry for the delay in getting back.

As soon as I have 5 minutes I'll check this out.

Thanks again,

Paul.
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 40054615
But doesn't "ListPathsXML" use xp_cmdshell?

What is wrong with "OPENROWSET( BULK"?
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 40055073
Mission Impossible?
Yes.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now