Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:54:23+00:00 2026-06-15T09:54:23+00:00

I have table which has one field (Information). Information =========== Hello World 1 This

  • 0

I have table which has one field (Information).

Information
===========
Hello World 1
This is testing message
How are  you

I want to create three text files (as number of rows are 3) which will have content based on value in rows.

So,

  • File1.txt will have Hello World 1
  • File2.txt will have This is testing message

How can we achieve this in SQL Server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:54:25+00:00Added an answer on June 15, 2026 at 9:54 am

    Try something like this:-

    use master
    go
    
    declare @DSQL Nvarchar(max)
    declare @counter int
    declare @maxrows int
    declare @filename Nvarchar(30)
    
    select @counter=1, @maxrows = 0
    
    create table t1 (
     sno int identity(1,1) not null,
     filename varchar(5),
     filecontent varchar(100)
    )
    
    insert into t1
    select 'FN1', 'Hello'
    UNION
    select 'FN2', 'Good Morning'
    UNION
    select 'FN3', 'How are you?'
    UNION
    select 'FN14', 'Where are you?'
    
    select @maxrows = count(*) from t1
    
    --SELECT * FROM T1
    
    while (@counter <= @maxrows)
    begin
      select @filename = filename from t1
       where sno = @counter
    select @DSQL = N'exec xp_cmdshell' + ' ''bcp "select filecontent from master.dbo.T1 where sno = ' + cast(@counter as nvarchar(10)) + '" queryout "d:\temp\' + @filename + '.txt" -T -c -S home-e93994b54f'''
    
    print @dsql
    exec sp_executesql @DSQL
       select @counter = @counter + 1
    end
    
    drop table t1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table, t1, which has fileds called userid, week and year fields.
I have a table which has several one to many relationships with other tables.
I have query table copyQuery which has Soil Condition has one of the columns,
i have a table which has many fields but i want to get count
I have a table which has a field called Sold , in that field
I have a table which contains around 50,000 records of information which has been
I have two tables, one table has some information in each row along with
I have a table in my database which has information about a bunch of
I have a table which has two text boxes and an image beside it
I have a table which has employee relationship defined within itself. i.e. EmpID Name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.