sql query variable not exactly unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sql query variable not exactly unix
# 1  
Old 12-04-2002
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 simple.

select * from price-file
where date between yesterday and today


I want yesterday and today to be a variable always set to system date and system date - 1

I know how to get the date in a unix script. How do I pass it to the sql and have it pick it up?


Newbie to sql..

thanks
# 2  
Old 12-04-2002
Data

And i posted this in the wrong forum. i clicked on scripting and when i submitted it ended up here. Smilie
# 3  
Old 12-04-2002
(I moved the thread into the correct forum.)

One solution is my datecalc script.

Other solutions have been posted from time to time as well. But we seem to have a database error that has rendered our search function into an interesting challenge.
# 4  
Old 12-09-2002
Try This

Code:
todays_date=`date +%m/%d/%C%y` #mm/dd/yyyy format
yesterdays_date=`TZ=MST31 date +%m/%d/%C%y`
echo "select * from price-file
      where date between '$yesterdays_date'
      and '$todays_date';" | dbaccess mydb >> sql.output

Embedding the SQL statement in a Unix Shell Script is one solution. The trickiest part is accurately calculating yesterday's date. As suggested, search the forum for more detail on this subject.

Last edited by jschanem; 12-10-2002 at 11:11 AM..
# 5  
Old 12-09-2002
Check out this thread


Hope it helps !!

~MK
minazk
# 6  
Old 12-10-2002
Best solution would be to use the date functions of sql. The informix sql may differ slightly, but in Oracle:
Code:
where date between sysdate - 1 and sysdate

which represents the last 24 hours, to this second.
Jimbo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Asign to variable ksh some values of sql query

Hi, I'm trying to asign to ksh varible some values of a sql query. The output query would be: xxxx 1 yyyy 2 I do: values=`$PATH_UTI/query_sh " select think1||'------'||think2 from some_table where think3 = '$1'; ... (2 Replies)
Discussion started by: mierdatuti
2 Replies

3. Shell Programming and Scripting

Run sql query after ssh in UNIX

I am running this test.ksh on server1. It successfully logins to server2 but runs the queries of query.sql on server1. query.sql is present in both server1 and server2 Can anybody please help. I need to run queries on server2 itself.:confused: Below is the test script... (10 Replies)
Discussion started by: shruthimithra
10 Replies

4. UNIX for Dummies Questions & Answers

Running a SQL Query from UNIX

Hi, Could you please help me on this. I have bulk of queries written in text file. I want to use those queries and want to execute from UNIX. I don't want to run this file as a sql file as this file will change every week. I want to run it in my environment as bulk sql statement from text... (1 Reply)
Discussion started by: abhii
1 Replies

5. UNIX for Advanced & Expert Users

Passing Hash variable in to sql query in perl

Hi Everyone, Can anyone help me how do i call hash variable in to sql query in perl. Please see the script below i have defined two Hash %lc and %tab as below $lc{'REFF'}='V_RES_CLASS'; $lc{'CALE'}='V_CAP_CLASS'; $lc{'XRPD'}='V_XFMR_CLASS'; $tab{'V_RES_CLASS'}='V_MFR_SERS';... (6 Replies)
Discussion started by: jam_prasanna
6 Replies

6. Shell Programming and Scripting

Execute SQL query in unix script

Hi I am new in unix. oracle and unix are installed in my sytem.i need the script which could connect to the oracle using username ,password and schema and can run the select * from tab query. Thanks vijay (8 Replies)
Discussion started by: vijays3
8 Replies

7. Shell Programming and Scripting

How to use sql data file in unix csv file as input to an sql query from shell

Hi , I used the below script to get the sql data into csv file using unix scripting. I m getting the output into an output file but the output file is not displayed in a separe columns . #!/bin/ksh export FILE_PATH=/maav/home/xyz/abc/ rm $FILE_PATH/sample.csv sqlplus -s... (2 Replies)
Discussion started by: Nareshp
2 Replies

8. Shell Programming and Scripting

Problem while storing sql query value in a variable

Hi, When i execute the below statement , the value is not getting stored in the variable. AnneeExercice=`sqlplus $LOGSQL/$PASSWORDSQL << FIN >> $GEMOLOG/gemo_reprev_reel_data_ventil_$filiale.trc SELECT bi09exercice FROM bi09_scenario WHERE bi09idfiliale=UPPER('de') AND ... (1 Reply)
Discussion started by: krishna_gnv
1 Replies

9. Shell Programming and Scripting

How to store the sql query's output in a variable

Hi, My requirement is : We are calling an sql statement from a UNIX session, and fetching data into some variables from a table .. now we are unable to access these variables from outside the SQL part. Please let me know how can I achieve this. Can you please share a code snippet which... (4 Replies)
Discussion started by: venkatesh_sasi
4 Replies

10. 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
Login or Register to Ask a Question