• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

how to open text file by T-SQL script?

how to do the following thing by T-SQL script?
open a text file, and count the number of specific character in the text.
1 Solution
Something like this will do the trick, depends how big your file is as well look at the size of the field holding the data
If its a lot of data you are better off reading in the by line add adding a record each time
then do your replace in the same way

You will need to drop the temp file after

CREATE PROCEDURE getmyFileSize(@myfile varchar(2000), @char2count varchar(1) )
      --Temporary table for getting details
      CREATE TABLE #tmp (sName VARCHAR(20000))  
      --Gets the data from file to Temp table
      BULK INSERT #tmp
         FROM @file
         WITH (ROWTERMINATOR = '\n')
      --returns the number of replacements assumes your char is not £
      SELECT replace(@char2count,"£") as 'Charcount'
DataFieldAuthor Commented:
excellent idea!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now