SQL in LINUX. Variable or Database


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SQL in LINUX. Variable or Database
# 1  
Old 06-18-2012
SQL in LINUX. Variable or Database

Dear Friends :-),

Need your help once again.

I have following SQL in a shell script to pick values from database
Code:
select date_stamp, time_stamp from logs
where date=31012012

However, at times we need to take these value(s) from a variable. To do this we have following query.
Code:
select $date_stamp, $time_stamp from logs
where date-31012012

Now I want to write this SQL such a way that it will check if the variable is null then it will pickup value from database, and if variable is not null then it will pick it from the variable.

Please guide me to do it efficiently as I got to do it for lacs of records.

Thanks
Anu.

Last edited by Franklin52; 06-18-2012 at 07:40 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 06-18-2012
Check if variable is null or not .
Code:
if [ -z $date_stamp -a -z $time_stamp ]
then
   echo " variable is null , selecting value from database"
   # select date_stamp, time_stamp from logs where date=31012012
fi

# 3  
Old 06-18-2012
The previous solution might falter in some shell versions. A small change to it:

Code:
if [ -z "$date_stamp" -a -z "$time_stamp" ]
then
   echo " variable is null , selecting value from database"
   # select date_stamp, time_stamp from logs where date=31012012
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Connect to database server and execute sql

I have a requirement and below is the detail. Create a shell script and needs to run in server "a". Connect to teradata database server "b". execute the .sql file from server "a" Save the output of the query to a file in server "a" Schedule this shell script to run every day for every 4... (1 Reply)
Discussion started by: MadhuSeven
1 Replies

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

3. Shell Programming and Scripting

SQL compare database

Hi , I have 2 databases which has same table names and I need to list entries of a particular table in database1 not existing in the same tablename of database2. eg : I have db1 having table name orders ad_d | code | start | end | amountscore | id | amount_class |... (1 Reply)
Discussion started by: siya@
1 Replies

4. Programming

pls. help with SQL database...

On the Linux systems, we have scripts which monitor disk usage. I want to take that data and feed that into SQL database. Can you give some advise. For example here is one of the file. I have many files like this but the format is same... 2012-09-24 04:36:14 2012-09-24 04:36:16 48414984... (3 Replies)
Discussion started by: samnyc
3 Replies

5. UNIX for Dummies Questions & Answers

shell/sql to get difference between two database

I have two queries query1 select IDW_SITE_NAME REGION,a.location_sid,a.CALENDAR_SID,count(*) from idw.vod_stream a, IDW_REF_DATA b where a.location_sid = b.location_sid and a.calendar_sid between 20110901 and 20110915 --this is start date parameter and end date parameter and... (5 Replies)
Discussion started by: qutesanju
5 Replies

6. Solaris

redirect solaris database from linux database..

hi.. i have a need .. my php runs on my linux redhat box with mysql.. i want my php code to refer another mysql database which is in solaris 10 x86... can u tell me the procedure .. how it can be done through php .. sorry am new to php... is it possible to redirect from linux mysql to... (7 Replies)
Discussion started by: senkerth
7 Replies

7. Programming

SQL for flat file database

I have a B+ tree flat file database which is used by the application we use. I would like to implement a SQL kind of access for that DB. I have implemented my data structures to parse and store the user written query for execution. But i would like to know, do we have any standard data... (2 Replies)
Discussion started by: kumaran_5555
2 Replies

8. Shell Programming and Scripting

Connecting to MS SQL database from bash (using unixODBC)

I've installed unixODBC and I would like to connect to a MS SQL (2005) database from a bash script. Can you post a code example? Thank you! :D J. (0 Replies)
Discussion started by: ph0enix
0 Replies

9. AIX

Install MySQL connector without local SQL database

Hello UNIX gurus, I need to install the mysql odbc connector with unixODBC on my AIX 5.3 machine. I have a mySQL database running on another server (Ubuntu 7.04). The SQL database works fine. The problem I am having is when trying to run ./configure for mysql-connector-odbc it seems to be looking... (1 Reply)
Discussion started by: raidzero
1 Replies

10. UNIX for Dummies Questions & Answers

Read SQL database from Unix...

Hi there, I am new here and looking for a bit of help... I don't don't know much about Unix but I've tried to include as much info as possible. We currently operate our system as a bespoke on SCO 5.05 with Informix databases. This includes a financials package called "Multisoft". Both... (0 Replies)
Discussion started by: uptheposh
0 Replies
Login or Register to Ask a Question