Generate Excel in SQL SERVER

Asked

Viewed 8,493 times

1

Good afternoon.

I need to generate an excel file by SQL SERVER. And I need to specify the data type of the cells in that file.

For example, in the value cells, set the data type to "R$" for example. In a cell with a percentage, already set the cell data type to "%".

In C# this is done with ease, but it is possible to do this in SQL SERVER?

I have the CUSTOMER table with the following extrusion:

NOME               DATANASCIMENTO         VALOR
Thiago Henrique    18-09-1988             52.50
Pedro Diniz        18-09-1988             12.67

I need to generate an excel file that exports this data where in the worksheet the column NOME has the data type with "Text", the column DATANASCIMENTO has the data type "Abbreviated Date" and the column VALOR has the die type "Currency"

Personal thank you.

  • Hello Thiago, your question is a little wide. It would be easier to get an answer if you explained better what you really need. For example, are you already exporting the data to Excel? Already have the query? Already have the conversion formula? This and other information is needed to get a good answer. If possible, add some example of what you really need.

  • @Randrade What I need is to generate an excel with the result of a query. I have no conversion formula. I will add the example.

  • In this case you have two questions. One of how to export and the other of how to "customize" the returned values. I suggest you open two questions, as they are two separate subjects.

1 answer

4

I am updating the answer with the export form via SQL command.

You can just copy and paste the data into an excel file as shown in the image below:

inserir a descrição da imagem aqui

Sql Server also has a "Wizard" to do this export. You can use it as follows:

Step 1: Right click on the desired bank > Task > Export Date.

inserir a descrição da imagem aqui

After that, you will start the Wizard for export. Just follow the steps given.

Step 2: Select the server and database you want to export from.

inserir a descrição da imagem aqui

Step 3: Select the generated file type (in your case, it will be Microsoft Excel), the location where it will be saved and the excel version.

inserir a descrição da imagem aqui

Step 4: At this time you will choose between copying the table or the complete tables (first option) or adding a query (query) to return the data.

inserir a descrição da imagem aqui

Step 4.1: Copy data from one or more Tables or views (Copy data from one or more tables).

Just select the table or tables that will have the exported data:

inserir a descrição da imagem aqui

Step 4.2: Write a query to especify the data to transfer (Write a query to specify the data to download)

Just add the query to the specified field.

inserir a descrição da imagem aqui

Step 5: Click on conclude on this screen or at the rear:

inserir a descrição da imagem aqui

After that, the file will be at the location specified in Step 3.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.