how to open text file by T-SQL script?

Posted on 2005-04-12
Last Modified: 2008-02-01
how to do the following thing by T-SQL script?
open a text file, and count the number of specific character in the text.
Question by:DataField
    LVL 1

    Accepted 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'

    Author Comment

    excellent idea!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Specialist

    HTML5 development skills are critical to all developers. HTML5 is the foundation to almost any development process. That's why business, design studios, development shops and other organizations need HTML5 developers. Get your foot in the door as a HTML5 specialist.

    Suggested Solutions

    Title # Comments Views Activity
    Visual xHarbour 1 47
    scores100 challenge 3 66
    SPLUNK REST  API call to Splunk to create and index? 2 39
    nestparen challenge 4 33
    This article will show, step by step, how to integrate R code into a R Sweave document
    This is an explanation of a simple data model to help parse a JSON feed
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now