Solved

Load file into SqlString variable using only TSQL.

Posted on 2014-02-28
5
72 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

914 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

15 Experts available now in Live!

Get 1:1 Help Now