Sponsored Content
Top Forums Shell Programming and Scripting How to store the sql query's output in a variable Post 302159494 by venkatesh_sasi on Friday 18th of January 2008 12:03:01 AM
Old 01-18-2008
Hi All,

Thanks alot for the quick help, I will test them and revert incase i face any issues.

Regards,
Venkatesh.Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sql query variable not exactly unix

I know htis isnt exactly unix.... but hopefully someone can help me or direct me someplace to get help. I can run sql queries in scripts against my informix db using: dbaccess mydb myquery.sql >> sql.output I need to write my script to select based on todays date. Its very... (5 Replies)
Discussion started by: MizzGail
5 Replies

2. Shell Programming and Scripting

How to store query multiple result in shell script variable(Array)

:) Suppose,I have one table A. Table A have one column. Table A have 10 rows. I want this 10 rows store into shell script variable. like #!/bin/ksh v_shell_var=Hi here in call oracle , through loop How can I store table A's 10 rows into v_shell_var (Shell Script Array). Regards, Div (4 Replies)
Discussion started by: div_Neev
4 Replies

3. Shell Programming and Scripting

script variable within a sql query

I created a script to read a csv file with four columns. The script also saved values of each col in a arry. In the script, i connected to db try to run a query to pull out data baisc on the values from the csv file. select Num from tableName where Sec_Num in ('${isin}') /*isin is an arry... (1 Reply)
Discussion started by: Sherry_Run
1 Replies

4. Shell Programming and Scripting

add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable? $result = odbc_exec($connect, $query); while ($row = odbc_fetch_array($result)) { echo $row,"\n"; } odbc_close($connect); ?> This will output hostnames: host1... (0 Replies)
Discussion started by: hazno
0 Replies

5. Shell Programming and Scripting

How to store the sql query output into txt file?

Hi I want ot save SQL query result in one txt file. for that i have written one code line sqlplus -s $dbstring @/usr/local/bin/sched/nightly_Cronjob/exec_123.sql >> /usr/local/bin/sched/nightly_Cronjob/result.txt but it is not working . database : Oracle so please advice me how can i... (7 Replies)
Discussion started by: Himanshu_soni
7 Replies

6. Shell Programming and Scripting

need to store query output fields in variables edit them and update the same in tables.

Hi , I have a query like select err_qty,drop_qty,unbld_qty,orig_qty from usage_data; I need to store the values of these fetched fields in variables, Need to edit them and update the new values into the table. Can anyone please help me in writing this piece of code:( (1 Reply)
Discussion started by: Rajesh Putnala
1 Replies

7. Solaris

SQL QUERY to Table Output

Hi I am trying to run sql query from solaris in csh script and send the output to email. Below is my sql query select p.spid,se.program seprogram, se.machine, se.username, sq.sql_text,sq.retrows from v$process p inner join v$session se on p.addr = se.paddr inner join ( select... (2 Replies)
Discussion started by: tharmendran
2 Replies

8. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

9. Shell Programming and Scripting

How to Assign the Output of an SQL Query to a Variable?

Hi iam new to shell scripting how to declare variables as redshift query and I have to compare two counts by using if condition . ex:count=select count(*) from prd; select count(*) from prd; select count(*) from tag; can any one help me . Please use CODE tags when displaying... (1 Reply)
Discussion started by: sam526
1 Replies

10. Shell Programming and Scripting

Sql query output count

Hi Team, below sql rerturn 20 records, the result set i am going to assign to one variable and it showing count is 1. and i don't use count() in sql query... based on count, i need to fail the script. No_of_step=`echo ${g_count} | wc -l` function gf_count() { g_count=`sqlplus -s... (8 Replies)
Discussion started by: bmk123
8 Replies
SQLSRV_QUERY(3) 														   SQLSRV_QUERY(3)

sqlsrv_query - Prepares and executes a query.

SYNOPSIS
mixed sqlsrv_query (resource $conn, string $sql, [array $params], [array $options]) DESCRIPTION
Prepares and executes a query. PARAMETERS
o $conn - A connection resource returned by sqlsrv_connect(3). o $sql - The string that defines the query to be prepared and executed. o $params - An array specifying parameter information when executing a parameterized query. Array elements can be any of the following: oA literal value oA PHP variable oAn array with this structure: array($value [, $direction [, $phpType [, $sqlType]]]) The following table describes the elements in the array structure above: Array structure +----------------------+---------------------------------------------------+ | Element | | | | | | | Description | | | | +----------------------+---------------------------------------------------+ | $value | | | | | | | A literal value, a PHP variable, or a PHP by-ref- | | | erence variable. | | | | |$direction (optional) | | | | | | | One of the following SQLSRV constants used to | | | indicate the parameter direction: SQL- | | | SRV_PARAM_IN, SQLSRV_PARAM_OUT, SQL- | | | SRV_PARAM_INOUT. The default value is SQL- | | | SRV_PARAM_IN. | | | | | $phpType (optional) | | | | | | | A SQLSRV_PHPTYPE_* constant that specifies PHP | | | data type of the returned value. | | | | | $sqlType (optional) | | | | | | | A SQLSRV_SQLTYPE_* constant that specifies the | | | SQL Server data type of the input value. | | | | +----------------------+---------------------------------------------------+ o $options - An array specifing query property options. The supported keys are described in the following table: Query Options +-----------------------+--------------------------------------+---+ | Key | | | | | | | | | Values | | | | | | | | Description | | | | | | +-----------------------+--------------------------------------+---+ | QueryTimeout | | | | | | | | | A positive integer value. | | | | | | | | Sets the query timeout in seconds. | | | | By default, the driver will wait | | | | indefinitely for results. | | | | | | |SendStreamParamsAtExec | | | | | | | | | | | | | TRUE or FALSE (the default is TRUE) | | | | | | | | Configures the driver to send all | | | | stream data at execution ( TRUE), or | | | | to send stream data in chunks ( | | | | FALSE). By default, the value is set | | | | to TRUE. For more information, see | | | | sqlsrv_send_stream_data(3). | | | | | | | Scrollable | | | | | | | | | SQLSRV_CURSOR_FORWARD, SQLSRV_CUR- | | | | SOR_STATIC, SQLSRV_CURSOR_DYNAMIC, | | | | or SQLSRV_CURSOR_KEYSET | | | | | | | | See Specifying a Cursor Type and | | | | Selecting Rows in the Microsoft SQL- | | | | SRV documentation. | | | | | | +-----------------------+--------------------------------------+---+ RETURN VALUES
Returns a statement resource on success and FALSE if an error occurred. EXAMPLES
Example #1 sqlsrv_query(3) example <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password" ); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "INSERT INTO Table_1 (id, data) VALUES (?, ?)"; $params = array(1, "some data"); $stmt = sqlsrv_query( $conn, $sql, $params); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } ?> NOTES
For statements that you plan to execute only once, use sqlsrv_query(3). If you intend to re-execute a statement with different parameter values, use the combination of sqlsrv_prepare(3) and sqlsrv_execute(3). SEE ALSO
sqlsrv_prepare(3), sqlsrv_execute(3). PHP Documentation Group SQLSRV_QUERY(3)
All times are GMT -4. The time now is 11:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy