How do I also get headers for a table extracted in an SQL query
조회 수: 43 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
The runsqlscript function will be removed in a future release. You can use the executeSQLScript function instead.
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!