SQLQueryValue
|
home |
Syntax:
=SQLQueryValue(Query [, Transpose] [,
Rownum])
=SQLQueryValueVolatile(Query [, Transpose] [,
Rownum])
Query (datatype String): SQL select statement to
retrieve the data
Query (datatype Range): Range of cells
containing the SQL select statement to
retrieve the data
Transpose (datatype Boolean): Optional; display rows as columns.
Rownum (datatype Number): Optional;
row number of the result row to display
Description:
The
SQLQueryValue function runs a query in the database and displays the result in
the cell. In the Query parameter the SQL statement should be given. If you
retrieve multiple columns (e.g. select col1, col2, col3 from mytable) then
SQL*XL will only display the value of the first column. It is therefore not
useful to list more than one column in your query. It is also
not
useful to retrieve more than one row. By default
SQLQueryValue will display row 1 unless you specify a different rownumber
in the Rownum variable
SQLXLQueryValueVolatile does exactly the same but this function will always be evaluated when Excel calculates.
Examples:
A1: =SQLQueryValue( "select ename from emp where empno
= 123" )
A2:
=SQLQueryValue( concatenate( "select ename from emp where empno = " ,
D12 ) )
A3: =SQLQueryValue( concatenate( "select sal from emp where
ename ='", E25 , "'") )
--Note that the function is A3 wraps the
string retrieved from E25 in single quotes.
A1: =SQLQueryValue( concatenate( "select
count(*) from ", , D10 )
--Note that this is dynamic sql where the value in the
cell represents the number of rows in the table name found in D10
A1: =
"select *"
A2: =
"from emp"
A3:
= SQLQueryValue( A1:A2)
See also: