Unix and db2 where condition issue(new line)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix and db2 where condition issue(new line)
# 1  
Old 02-22-2012
Unix and db2 where condition issue(new line)

Hi

I am extracting a column value(DESCRIPTION) from one table and passing it to another db2 statement in a shell code to fetch some value(ID) but the value when passed in where condition is taking as newline+value.

Please find the out put when executed:
Code:
 
+ echo description is :::: $DESCRIPTION
description is :::: AAAA

Though it is not giving any line here but the above description when passed in below code:
Code:
ID_LIST=`db2 -x "select distinct SITE_ID from TABLEA where REGION='$DESCRIPTION' for fetch only with ur"`

is giving the below output
Code:
+ + db2 -x select distinct SITE_ID from TABLEA where REGION='
AAAA' and report_dt='31/03/2012' for fetch only with ur
 
'AAAA' is replaced as
'
AAAA'

A new line in the value is creating a issue which results in now data from the table.

Could you give me a reason and solution for the problem? Thanks in Advance

Moderator's Comments:
Mod Comment How to use code tags

Last edited by vbe; 02-22-2012 at 08:53 AM..
# 2  
Old 02-22-2012
Not to use too many tools for a simple solution, just write your query in SQL string language in the first query and just send it to the second SQL client to run. The results are viewable, predictable and reliable (robust), unless someone puts a lf in the db string, and even then, there are tools to remove it, like substr() and index(), as I recall offhand. You just need options or sh filtering to remove headers and the like. Sometimes there are functions to reparse a generated string in the first session, like to access a generated table. Then, there are views or derived tables of unions, so many tables can be one.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

DB2 - Performance Issue using MERGE option

Dear Team, I am using DB2 v10.5 and trying to load huge data using MERGE option ( 10-12 Million) using below query. Basically it loads data from staging to target . Staging table schemaname.Customer_Staging has 12 Million records . Runs for 25 Mins for just select query. But while doing merge... (2 Replies)
Discussion started by: Perlbaby
2 Replies

2. Shell Programming and Scripting

Find line then evaluate text on next line, print when condition is met

Hello, I am looking for a specific situation in a text file. The conditions are, > <CompoundName> InChI=1S/C5H12NO2/c1-5(2)4-8-6(3)7/h5H,4H2,1-3H3/q+1 I am looking for cases where the line "> <CompoundName>" is followed by a line that contains the string "InChI=" without regard to... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

3. Shell Programming and Scripting

UNIX with DB2 error status Issue

I have a shell script main.ksh We are calling dbscript.ksh from main.ksh I am using select statement in dbscript.ksh but there is a problem with the select statement in dbscript.ksh but still echo $? is showing as zero. I am using DB2 commands in dbscript.ksh Main.ksh dbscript.ksh echo $? ... (13 Replies)
Discussion started by: vamsi.valiveti
13 Replies

4. Shell Programming and Scripting

Issue on executing db2 queries through shell script

hi i am trying to execute db2 queries through shell script. it's working fine but for few queries is not working ( those queries are taking time so the script is not waiting to get the complete the execution of that query ) could you please any one help me on this is there any wait... (1 Reply)
Discussion started by: bhaskar v
1 Replies

5. Shell Programming and Scripting

If Condition Issue in UNIX

Hi I am trying to do a "IF" Condition in UNIX where we compare EACH file size in a directory with a SIZE (Parameter passed) If Each File size EXCEEDS parameter passed SIZE then we manipulate the file. Somehow the IF condition do not work ?? (is this Variable decalration issue ??) ... (9 Replies)
Discussion started by: Pete.kriya
9 Replies

6. Shell Programming and Scripting

/db2home full issue in db2

Hi all, I am new for linux environment, and i am working as a DBA. I am facing some issues in OS level: In our dev boxes /db2home under this directory i'm not finding any folder but it's showing 98% used . /dev/dm-14 5.0G 4.6G 115M 98% /db2home # ls -lrt total 16... (1 Reply)
Discussion started by: suresh_target
1 Replies

7. UNIX for Dummies Questions & Answers

How to connect to DB2 using UNIX

I am new to Putty, Unix and DB2 and this is what I am working on right now. I installed Putty I got access to username / pwd I got Unix usrname/Pwd.also got the home directory once I login into putty I get the screen and it shows $ sign From here how do I connect to DB2 database? I have... (2 Replies)
Discussion started by: JayDoshi
2 Replies

8. Shell Programming and Scripting

DB2 Connect issue

Hi i m trying to connect DB2 via unix. it is successfully connect. but the connect is getting disconnect . below is the query , countvalue=$(db2 "connect to <Database> user <username> using <Password>" | db2 -x 'select count(*) from <tablename>' ); echo $countvalue while... (2 Replies)
Discussion started by: baskivs
2 Replies

9. Shell Programming and Scripting

need help with UNIX, awk and DB2

Hi i am working on a script which takes a parameter file as input . this parameter file is having SQL statements. I am fetching column names from the output of SQL file using following code: while read Record1 do SQLQuery=`echo $Record1 | awk '{printf $0 }'` ... (2 Replies)
Discussion started by: manmeet
2 Replies

10. Shell Programming and Scripting

connect to Db2 thru Unix

I need to connect to DB2 through Unix and check whether the database is up or not. We are planning to use Neon shadow direct to connect to the same. I would like to know how to pass parameters to neon shadow direct. Any guidance/help in this regard would be helpful. My unix box is AIX 1. ... (3 Replies)
Discussion started by: ranj@tcs
3 Replies
Login or Register to Ask a Question