Export data from a sql database to a .TXT

Hello Uipath community, this is my first time doing a question here, I have a flow that connects to a database that I have as a test in sql server,

The structure of the database is as follows:

e1

Attached sql script

USE [master]
GO
/****** Object:  Database [uipath]    Script Date: 11/5/2022 18:24:32 ******/
CREATE DATABASE [uipath]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'uipath', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\uipath.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
 LOG ON 
( NAME = N'uipath_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\uipath_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
 WITH CATALOG_COLLATION = DATABASE_DEFAULT
GO
ALTER DATABASE [uipath] SET COMPATIBILITY_LEVEL = 150
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [uipath].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [uipath] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [uipath] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [uipath] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [uipath] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [uipath] SET ARITHABORT OFF 
GO
ALTER DATABASE [uipath] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [uipath] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [uipath] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [uipath] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [uipath] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [uipath] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [uipath] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [uipath] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [uipath] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [uipath] SET  ENABLE_BROKER 
GO
ALTER DATABASE [uipath] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [uipath] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [uipath] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [uipath] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [uipath] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [uipath] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [uipath] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [uipath] SET RECOVERY FULL 
GO
ALTER DATABASE [uipath] SET  MULTI_USER 
GO
ALTER DATABASE [uipath] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [uipath] SET DB_CHAINING OFF 
GO
ALTER DATABASE [uipath] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [uipath] SET TARGET_RECOVERY_TIME = 60 SECONDS 
GO
ALTER DATABASE [uipath] SET DELAYED_DURABILITY = DISABLED 
GO
ALTER DATABASE [uipath] SET ACCELERATED_DATABASE_RECOVERY = OFF  
GO
EXEC sys.sp_db_vardecimal_storage_format N'uipath', N'ON'
GO
ALTER DATABASE [uipath] SET QUERY_STORE = OFF
GO
USE [uipath]
GO
/****** Object:  Table [dbo].[customer]    Script Date: 11/5/2022 18:24:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[customer](
	[name] [varchar](50) NULL,
	[last_name1] [varchar](50) NULL,
	[Lastname2] [varchar](50) NULL,
	[salary] [real] NULL,
	[pass] [varchar](10) NULL
) ON [PRIMARY]
GO
USE [master]
GO
ALTER DATABASE [uipath] SET  READ_WRITE 
GO

I have already made the successful connection to the database and run the sql query without any problems and display the data in a WriteLine:

I am writing the result by console:

e1

what I am looking for is to generate a txt with that data but separated by a “│” as a separator, for example

name│last_name1│Lastname2│salary│pass
Yeyner│Miranda│Escobar│30000│1
Yeyner│Escobar│Miranda│15000│1
Juan│Villanueva│Nieto│50000│2
Pedro│Villanueva│Perez│26000│3
Erika│Villanueva│chavez│67000│4

If anyone has an idea how I should do it, I appreciate your comments.

Because it’s my first time, it won’t let me attach the process generated in uipath, I’m attaching a download link:
TestDatabase_to_TXT.zip - Google Drive

Hey @Yeyner_Osmar_Escobar

We had a similar thread for which we figured out the solution, trying to search and get it. Will update.

Thanks
#nK

Hello @Yeyner_Osmar_Escobar

Plz use replace function.

OutputQuery1.Replace(”,”,”|”)

It will replace comma with | in the output.

Else use can use Find/Replace activity also

Hello @Nithinkrishna

Do you remember how they solved it?

Hey @Yeyner_Osmar_Escobar

I the one provided the solution btw so we will write it again no worries.

Let me search give me sometime pls, hope u r okay.

Thanks
#nK

Hey @Yeyner_Osmar_Escobar

Here it is,

dt_Data.AsEnumerable.Select(Function(row) String.Join(Environment.Newline.ToCharArray, String.Join("|", row.ItemArray)))

Try the above please.

Thanks
#nK

Thanks you @Nithinkrishna

Very useful your solution @Rahul_Unnikrishnan , another way to do it

1 Like

Hey @Yeyner_Osmar_Escobar

Please make sure your content doesn’t have comma inside it which may be a risk as it replace that as well.

Thanks
#nK

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.