Sponsored Content
Top Forums Shell Programming and Scripting Getting variable from a query Post 302784007 by sandy162 on Thursday 21st of March 2013 09:43:52 AM
Old 03-21-2013
Getting variable from a query

Hi,

I need to get a variable HMAX_TBL_ID and then use it in second select query. The first select statement returns few leading white spaces for ex : 12345
so when I run the script HMAX_TBL_ID does not return the "12345" , it returns blank.
Please let me know what I am missing.


Code:
HMAX_TBL_ID=`psql -U ${PG_USER} -h ${PG_HOST} -d ${PG_DB} -p ${PG_PASS} -t -c "select stp_ctr_fetch_module_tbl_id('ATTRIB', 'GET')"` | sed -e 's/^[ \t]*//'

        echo -e "This is max table id in ${HMAX_TBL_ID} "

        if [ $? -ne 0 ]
        then
                echo -e " Error while getting the maximun table id processed"
        fi


  psql -U ${PG_USER} -h ${PG_HOST} -d ${PG_DB} -p ${PG_PASS} -t -c "select distinct tbl_id from tbl_ctr_module_tbl where tbl_id between ${LAST_PROCESSED_TABLEID} and ${HMAX_TBL_ID}" | sed '/^$/d' > ${TBL_ID_FILE}

 

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

storing database query in a variable

I am executing a SQL query in Unix Server: select status,location from user_information where request_id='DS-43720' In shell script I am writing this query in the below manner: echo "select status,location from user_information where request_id='DS-43720' ;" >> $directory/info.sql ... (3 Replies)
Discussion started by: debu
3 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. UNIX for Dummies Questions & Answers

Redirect Query o/p to variable

Hi, I wanted to o/p the number of rows in a table to a variable in linux. How can i achieve this. I wrote the query and its settings like feedback, pagesize line size in a file and using this file as a parameter to the sqlplus command. now can i redirect the o/p of that query to a variable.... (2 Replies)
Discussion started by: Swapna173
2 Replies

5. 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

6. UNIX for Dummies Questions & Answers

how to - redirect query results to a variable

How can I send the results of a query to a unix variable. I basically want to run a query then do some logic on the results. Trying to redirect the result into a variable I define in the script. select count(*) as counter from table - nut to redirect the "count" returned from the query... (2 Replies)
Discussion started by: rstone
2 Replies

7. Shell Programming and Scripting

How to use a variable in insert query?

My script contains as follows, VALUE=`sqlplus un/pwd <<EOF > OB.txt set pagesize 0 feedback off verify off heading off echo off select max(1) from table1; exit; EOF` insert into table2 values(1, 'The max value is $value',...); i need the value of VALUE to be inserted after 'The max... (2 Replies)
Discussion started by: savithavijay
2 Replies

8. Shell Programming and Scripting

Formating of query variable in perl

Hi , I am facing error in perl when I assign a below query in a varibale $query because of new line charchters $query= SELECT XYZ , ABC , c2 , c3 , c4 FROM t1 how can i get rid of new line charchters with out changing the... (2 Replies)
Discussion started by: gvk25
2 Replies

9. Shell Programming and Scripting

Query on fetching a value of variable in script

I have below 3 files in a directory : oktest.txt okcode.txt okfun.txt I was writing a small shell script to just print the names of three files where I took a variable a and assigned it a value ok. a=ok echo "Three files are : $atest.txt $acode.txt $afun.txt" But when I run... (3 Replies)
Discussion started by: simpltyansh
3 Replies

10. Shell Programming and Scripting

How to pass variable to a query?

Hi All, How to pass date variable to a query? I have tried the below one , but it's not working. ost.ksh #!/bin/ksh v_date=$1 var=$(sqlplus -s $ORACON <<ENDOFSQL SELECT TO_DATE('$v_date','DD-MON-YYYY'),-1) FROM DUAL; exit; ENDOFSQL ) #End I have executed as below. (7 Replies)
Discussion started by: ROCK_PLSQL
7 Replies
MSSQL_FIELD_TYPE(3)													       MSSQL_FIELD_TYPE(3)

mssql_field_type - Gets the type of a field

SYNOPSIS
string mssql_field_type (resource $result, [int $offset = -1]) DESCRIPTION
Returns the type of field no. $offset in $result. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). o $offset - The field offset, starts at 0. If omitted, the current field is used. RETURN VALUES
The type of the specified field index on success or FALSE on failure. EXAMPLES
Example #1 mssql_field_type(3) example <?php // Connect to MSSQL and select the database mssql_connect('MANGOSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php'); // Send a select query to MSSQL $query = mssql_query('SELECT [name] FROM [php].[dbo].[persons]'); // Print the field type and length echo ''' . mssql_field_name($query, 0) . '' is a type of ' . strtoupper(mssql_field_type($query, 0)) . '(' . mssql_field_length($query, 0) . ')'; // Free the query result mssql_free_result($query); ?> The above example will output something similar to: SEE ALSO
mssql_field_length(3), mssql_field_name(3). PHP Documentation Group MSSQL_FIELD_TYPE(3)
All times are GMT -4. The time now is 07:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy