Read contents from txt file using T-SQL [duplicate] - tsql

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
SQL Server File Operations?
Is there by any chance I could use T-SQL to read the first line of a txt file?
Actually, I have a csv file and the first line is the name of all hundreds of columns. I have already coded the part where I could use the first line to generate a table with all that columns. So, really want to figure out how to do the reading part.

You could look at the BULK INSERT statement.

Related

Matlab data pull and save [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
What I'm attempting to do is simple:
Given an excel dataset and user defined inputs, open the associated excel file, pull the associated information for the user inputted information and save this information in a separate excel file.
I've already developed a list of values and the program recognizes user input with associated checks. I'm stuck on getting Matlab to use this information to open the correct dataset, I don't know how to get Matlab to pull a row/column in excel with a silent open and I don't know how to get it to save that data into a separate excel file. Any help would be appreciated, thank you.
Consider using the functions readtable, and writetable if you have a recent MATLAB (anything more recent than R2013b). The readtable function will 'silently' read data from a specific worksheet in an Excel file into a MATLAB table variable. From there you can 'query' the table to find the specific rows you want and write the result to a new excel table with writetable.
Using readtable, you can specify the range of data with the parameters sheet and range.
requested_data = readtable(excel_file, ...
'sheet',input_sheet_name, ...
'range',input_data_range);
and write the data to another Excel file with
writetable(requested_data,ouput_excel_file, ...
'sheet',output_sheet_name, ...
'range',output_data_range);
Note: Remember to set the values for excel_file, input_sheet_name, input_data_range, output_excel_file, output_sheet_name, and output_data_range before running above commands.
Querying the table to access data in your table. One way would be to use ismember as in this answer.
Finally, use writetable to store the values.
See also: sheetnames, detectImportOptions, and SpreadsheetImportOptions

Write parquet with partitionby vs. just a loop [duplicate]

This question already has answers here:
Overwrite only some partitions in a partitioned spark Dataset
(3 answers)
Closed 2 years ago.
Let's say have a script which writes a parquet file every week in 2 partitions: DAY and COUNTRY, in a FOLDER.
SOLUTION 1:
df.write.parquet(FOLDER, mode='overwrite',
partitionBy=['DAY', 'COUNTRY'])
The problem with this is that if later you want to rerun the script just for a specific country and date due to corrupted data in that partition, it will delete the whole folder's contents, and write in data just for the speciffic day/country.
APPEND also doesnt solve it, it would just append the correct data to the wrong one.
What would be ideal is that if the above command ONLY overwrote the DAY/COUNTRY combos which the df has.
SOLUTION 2:
Make a loop:
for country in countries:
for day in days:
df.write.parquet(FOLDER/day/country, mode='overwrite')
This works, because if I run the script, it only overwrites the files in the specific FOLDER/day/country, it just feels so wrong. Any better alternative?
If you are using spark 2.3 or above, you can create a partitioned table and
set the spark.sql.sources.partitionOverwriteMode setting to dynamic
spark.conf.set("spark.sql.sources.partitionOverwriteMode","dynamic")
df.write.mode("overwrite").insertInto("yourtable")

text size limitation in PgAdmin query [duplicate]

This question already has answers here:
incomplete information from query on pg_views [duplicate]
(2 answers)
Closed 7 years ago.
I want to get the source code of a function in my db.
I run this query:
select proname,prosrc from pg_proc where...
However when I copy the data in the procsrc field it copy only some of the function code, the whole code is not shown. I suspect that somewhere in the preference there is a text size limit.
How do I fix it?
Character Types
Text type has unlimited length. There are another problem.
Or try to change Max characters per column option.
File > Options > Query Tool > Max. characters per column
Max characters per column - Use the Max characters per column field to
specify the maximum length of data displayed in a single column.

How to increase display length in pg admin tool [duplicate]

This question already has answers here:
pgAdmin III Why query results are shortened?
(2 answers)
Closed 6 years ago.
I have a dumb problem. Basically I just upgraded from pgsql 8.4 to 9.1 and upgrade to pgAdmin 1.20.
I have some tables that have large text fields and in the previous query tool I could query a row and copy-paste the data out of it to modify. In this case, I had a table that stored queries that I could run.
Once I upgraded to the new pgAdmin version, when I use the tool and query a row to pull out the text from a field in that row, it truncates the result and ends with an ellipsis (...).
I tried figuring out how to increase the mem on this so it doesn't truncate after 100 characters or so but couldn't.
Anybody have any ideas??
In pgAdmin options, you can change the length of the field. Do the following,
Go to:
File > Options > Query Tool > Max. characters per column
By default it is 256, you can increase it accordingly.
Hope this helps
Marlon Abeykoon's answer is good, but if you want a one-off output and don't want to change settings, then simply output to a file (two buttons along from the usual green 'go' arrow). This saves the entire output in a csv file.

SubDataSet in iReport [duplicate]

This question already has answers here:
Multiple queries in a single jasper document
(2 answers)
Closed 9 years ago.
I want to use multiple queries in my report. But the main report allows me only one main query, however, I have found a way to have multiple queries in my report and that is done by subdataset in iReport. But I am unable to access the fields of my subdataset in my main-report. How to do that?
Thanks!
To view your sub data set you must use it in a chart, list, table etc.
Here is a great explanation:
Multiple queries in a single jasper document