SQL data extraction

Hai,
I have to extract data from my SQL
Database is : client info
Table name is: production order
I need to extract data from SQL and stored in excel
1. I want Top 13 datas
2. I want bottom 5 datas only

How can I achieve this please explain me

Thanks & regards,
Sivasankar

@siva_sankar

Use Execute Query query to fetch data from Database and it will give output as DataTable. And then use Write Range activity and pass above output DataTable to write into Excel file.

Hi @siva_sankar

How about Using below!
—> To take 13 datarows DT.AsEnumerable.Take(13).CopyToDatatable
---->To take last five datarows DT.AsEnumerable.skip(DT.Rows.count-5).CopyToDatatable**

Regards

3 Likes

Here Dt is mention as our sql tablename right

Hi @siva_sankar

Dt refers to the Datatable Which re you getting Out Dt from Using ExecuteQuery Activity!

Regards

1 Like

It’s through error like this

Hey,
in ‘sql’ field you have to use your sql query.
So use something like this:

Select top 15 *
from [production order]

1 Like

The SQL field in the activity property expects a String that contains your script.
For example:
“SELECT field1, field2, field3 FROM table”

I believe that the filters mentioned by other colleagues are applied after extracting information from the database to a DataTable type variable.

Your question is about how to filter the DataTable variable or how to make the script to extract data from the DB?

Hi @siva_sankar

For better understanding refer to the screenshot below!

Regards

1 Like

Can you provide that assign activit value from screenshot again I am getting error

@siva_sankar

Try Converting from string to datatable variable

and Use Write range to write the datatable

Regards

1 Like

@pravin_calvin thank you so much

I am getting my datas in correct way thanks a lot folks :call_me_hand::call_me_hand::call_me_hand::call_me_hand:
Happy Christmas :christmas_tree: and happy new year!!!

Happy automation!!
Thanks & regards,
Sivasankar

1 Like

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