フィルターのクリア

How do I also get headers for a table extracted in an SQL query

14 ビュー (過去 30 日間)
Thomas Skov
Thomas Skov 2020 年 1 月 16 日
コメント済み: Thomas Skov 2020 年 1 月 24 日
When I run:
>> results = runsqlscript(conn,'scriptfile');
I get a results output where the data is without the headers I can see when I run the same sql script via another program. How do I also get the headers in the matlab environment?

回答 (1 件)

Chidvi Modala
Chidvi Modala 2020 年 1 月 24 日
From my understanding, you are trying to get column headers from table. When the SQL script executes, it returns two cursor objects that contain the imported data from each query in a cursor object array. You can use the following example to extract column headers from a table
datasource = 'MS SQL Server Auth';
conn = database(datasource,'',''); % Create an ODBC database connection
scriptfile = 'compare_sales.sql'; % Run the SQL script
results = runsqlscript(conn,scriptfile);
data = results(2).Data; % Display the imported data for the second query.
names = columnnames(results(2)) % Retrieve column header names from the second query
You can refer to thisdocumentation
The runsqlscript function will be removed in a future release. You can use the executeSQLScript function instead.
  1 件のコメント
Thomas Skov
Thomas Skov 2020 年 1 月 24 日
Thanks for the nice answer. However, I have the issue that my results output:
results = runsqlscript(conn,scriptfile);
does not contain two objects which mean I cannot run:
data = results(2).Data;
My cursor is only a 1x1 cursor.
Thanks in advance

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by