Dear readers of our blog, we'd like to recommend you to visit the main page of our website, where you can learn about our product SQLS*Plus and its advantages.
 
SQLS*Plus - best SQL Server command line reporting and automation tool! SQLS*Plus is several orders of magnitude better than SQL Server sqlcmd and osql command line tools.
 

REQUEST COMPLIMENTARY SQLS*PLUS LICENCE

Enteros UpBeat offers a patented database performance management SaaS platform. It proactively identifies root causes of complex revenue-impacting database performance issues across a growing number of RDBMS, NoSQL, and deep/machine learning database platforms. We support Oracle, SQL Server, IBM DB2, MongoDB, Casandra, MySQL, Amazon Aurora, and other database systems.

Chapter 2: HTML Data Output

2 July 2020

Chapter 2: HTML Data Output

SQLS*Plus for SQL Server Data Output – HTML Data Output, CSV Data Output, JSON Data Output, Vertical Data Output, and Column Autoformatting.

HTML Data Output

Use “set markup html on|off” command to output data in HTML format

Sample SQL script for HTML output:

D:\sqlsplus>type t2.sql

set pages 10

ttitle LEFT 'this is a top title'

set markup html on
spool xx.htm

select top 25 name n1, id, name n2 from sysobjects;

spool off

set markup html off

host xx.htm

HTML output:

SQLS*Plus for SQL Server Data Output

CSV Data Output

Use “set output csv” command to output data in CSV format.

Sample SQL script for CSV output:

0:sa@192.168.1.160> set output csv
0:sa@192.168.1.160> set head off
0:sa@192.168.1.160> set pages 0

CSV output:

0:sa@192.168.1.160> select name,crdate from sys.sysobjects;
"sysrowsetcolumns","2005-10-14 01:36:15.923",
"sysrowsets","2005-10-14 01:36:15.910",
"sysallocunits","2005-10-14 01:36:15.910",
"sysfiles1","2003-04-08 09:13:38.093",
"syshobtcolumns","2005-10-14 01:36:15.940",
"syshobts","2005-10-14 01:36:15.923",
"sysftinds","2005-10-14 01:36:17.063",
"sysserefs","2005-10-14 01:36:15.940",
"sysowners","2005-10-14 01:36:17.050",
"sysprivs","2005-10-14 01:36:15.877",
"sysschobjs","2005-10-14 01:36:15.987",

JSON Data Output

Use “set output json” command to output data in JSON format.

Sample SQL script for JSON output:

0:sa@192.168.1.160> set output json
0:sa@192.168.1.160> set head off
0:sa@192.168.1.160> set pages 0

JSON output:

0:sa@192.168.1.160\SQLSERVER2008> select * from department order by dept_id;
{ "dept_id" : "10", "last_name" : "Jackson", "salary" : "50000", "bonus" : "12501.78" }
{ "dept_id" : "10", "last_name" : "Sally", "salary" : "55000", "bonus" : "13750" }
{ "dept_id" : "10", "last_name" : "Major", "salary" : "30000", "bonus" : "7500" }
{ "dept_id" : "10", "last_name" : "Mimon", "salary" : "38000", "bonus" : "9500" }
{ "dept_id" : "10", "last_name" : "Karla", "salary" : "58000", "bonus" : "14500" }
{ "dept_id" : "10", "last_name" : "Major", "salary" : "34000", "bonus" : "8500" }
{ "dept_id" : "10", "last_name" : "Mason", "salary" : "39000", "bonus" : "9750" }
{ "dept_id" : "10", "last_name" : "Mason", "salary" : "39000", "bonus" : "9750" }
{ "dept_id" : "10", "last_name" : "Jackson", "salary" : "50000", "bonus" : "12501.78" }
{ "dept_id" : "10", "last_name" : "Sally", "salary" : "55000", "bonus" : "13750" }
{ "dept_id" : "10", "last_name" : "Major", "salary" : "30000", "bonus" : "7500" }
{ "dept_id" : "10", "last_name" : "Mimon", "salary" : "38000", "bonus" : "9500" }
{ "dept_id" : "10", "last_name" : "Karla", "salary" : "58000", "bonus" : "14500" }
{ "dept_id" : "10", "last_name" : "Major", "salary" : "34000", "bonus" : "8500" }
{ "dept_id" : "10", "last_name" : "Mason", "salary" : "39000", "bonus" : "9750" }
{ "dept_id" : "10", "last_name" : "Mason", "salary" : "39000", "bonus" : "9750" }
{ "dept_id" : "20", "last_name" : "Smith", "salary" : "45000", "bonus" : "23000" }
{ "dept_id" : "20", "last_name" : "<NULL>", "salary" : "65000", "bonus" : "29000" }
{ "dept_id" : "20", "last_name" : "Major", "salary" : "78000", "bonus" : "" }
{ "dept_id" : "20", "last_name" : "Smith", "salary" : "75000", "bonus" : "18750" }
{ "dept_id" : "20", "last_name" : "Jefferson", "salary" : "90000", "bonus" : "22500" }
{ "dept_id" : "20", "last_name" : "Smith", "salary" : "45000", "bonus" : "23000" }
{ "dept_id" : "20", "last_name" : "<NULL>", "salary" : "65000", "bonus" : "29000" }
{ "dept_id" : "20", "last_name" : "Major", "salary" : "78000", "bonus" : "" }
{ "dept_id" : "20", "last_name" : "Smith", "salary" : "75000", "bonus" : "18750" }
{ "dept_id" : "20", "last_name" : "Jefferson", "salary" : "90000", "bonus" : "22500" }
{ "dept_id" : "30", "last_name" : "Sandy Jackson", "salary" : "38000", "bonus" : "19000" }
.…

Vertical Data Output

Use “set vout on” command to output data in vertical format, where each column is printed on its own line. Vertical output format is helpful when outputting data from a tables with many columns.

Sample SQL script for CSV output:

0:sa@192.168.1.160> set vout on

Vertical output:

0:sa@192.168.1.160> select name,crdate from sys.sysobjects;

name | sysrowsetcolumns
crdate| 2005-10-14 01:36:15.923

name | sysrowsets
crdate| 2005-10-14 01:36:15.910

name | sysallocunits
crdate| 2005-10-14 01:36:15.910

name | sysfiles1
crdate| 2003-04-08 09:13:38.093

Column Autoformatting

Use “set autoformat <table>” command to automatically format table columns to optimally size column sizes for character and numeric fields.

set autoformat supports 2 parameters:

maxsize – defined maximum size for long character columns, default is 40 characters sample – defined sample size for table data selection to identify optimal columns sizes, default is 5%.

Sometime default sample is not enough and for small table recommendation is to set sample to 50%-100%.

Sample table columns autoformatting:

0:sa@192.168.1.160\SQLSERVER2008> set autoformat SalesLT.Customer

Unable to create automatic column formatting. Please increase sample size and retry:

0:sa@192.168.1.160\SQLSERVER2008> set autoformat SalesLT.Customer sample 50
0:sa@192.168.1.160\SQLSERVER2008> col
COLUMN MIDDLENAME
FORMAT A10

COLUMN CUSTOMERID
FORMAT 9999999999

COLUMN PASSWORDHASH
FORMAT A40

COLUMN SALESPERSON
FORMAT A24

COLUMN COMPANYNAME
FORMAT A36

COLUMN PASSWORDSALT
FORMAT A12

COLUMN TITLE
FORMAT A5

COLUMN LASTNAME
FORMAT A22

COLUMN FIRSTNAME
FORMAT A15

COLUMN SUFFIX
FORMAT A6

COLUMN EMAILADDRESS
FORMAT A34

COLUMN PHONE
FORMAT A19


Download SQLS*Plus manual in PDF format


 
Tags: , , , , , ,

MORE NEWS

 

Preamble​​NoSql is not a replacement for SQL databases but is a valid alternative for many situations where standard SQL is not the best approach for...

Preamble​​MongoDB Conditional operators specify a condition to which the value of the document field shall correspond.Comparison Query Operators $eq...

5 Database management trends impacting database administrationIn the realm of database management systems, moreover half (52%) of your competitors feel...

The data type is defined as the type of data that any column or variable can store in MS SQL Server. What is the data type? When you create any table or...

Preamble​​MS SQL Server is a client-server architecture. MS SQL Server process starts with the client application sending a query.SQL Server accepts,...

First the basics: what is the master/slave?One database server (“master”) responds and can do anything. A lot of other database servers store copies of all...

Preamble​​Atom Hopper (based on Apache Abdera) for those who may not know is an open-source project sponsored by Rackspace. Today we will figure out how to...

Preamble​​MongoDB recently introduced its new aggregation structure. This structure provides a simpler solution for calculating aggregated values rather...

FlexibilityOne of the most advertised features of MongoDB is its flexibility.  Flexibility, however, is a double-edged sword. More flexibility means more...

Preamble​​SQLShell is a cross-platform command-line tool for SQL, similar to psql for PostgreSQL or MySQL command-line tool for MySQL.Why use it?If you...

Preamble​​Writing an application on top of the framework on top of the driver on top of the database is a bit like a game on the phone: you say “insert...

Preamble​​Oracle Coherence is a distributed cache that is functionally comparable with Memcached. In addition to the basic function of the API cache, it...

Preamble​​IBM pureXML, a proprietary XML database built on a relational mechanism (designed for puns) that offers both relational ( SQL / XML ) and...

  What is PostgreSQL array? In PostgreSQL we can define a column as an array of valid data types. The data type can be built-in, custom or enumerated....

Preamble​​If you are a Linux sysadmin or developer, there comes a time when you need to manage an Oracle database that can work in your environment.In this...

Preamble​​Starting with Microsoft SQL Server 2008, by default, the group of local administrators is no longer added to SQL Server administrators during the...