ryanW
April 13, 2009, 2:47am
1
Hi Everyone,
I need to assign the value to the variable after selection.
Anyone can help me?
for example:
data_type_SQL=$($CONNECT cat <<-__EOF__
SET NOCOUNT ON
select location_type, location_id, warehouse from JEALOCATION where
LOCATION_ID="$data_LocID_SQL"
for "data_type_SQL" will store the content after selected from databse.
the content should be
->>> |locationtype|locationID|warehouse|
How to make them to assignment to the varuable that i decrela?
local_ty=locationtype
local_id=locationID
wareH=warehouse
thank you
sauron
April 13, 2009, 4:41am
2
Hi,
echo the reply from DB
local_ty=$(echo " |locationtype|locationID|warehouse|" | cut -d\| -f2)
local_id=$(echo " |locationtype|locationID|warehouse|" | cut -d\| -f3)
wareH=$(echo " |locationtype|locationID|warehouse|" | cut -d\| -f4)
Bye
ryanW
April 13, 2009, 6:12am
3
Hi Sauron..
Thank you again..
the way u teach me.. is working...
but..
the local_ty and local_id no value after i debug in the log..
here is the code.
select LOC_TYPE, LOCATION_ID, WAREHOUSE from JEALOCATION where
LOCATION_ID="$data_LocID_SQL"
data_type_SQL=|G |NRTW |NRT |
localty=$(echo " |$LOC_TYPE|$LOCATION_ID|$WAREHOUSE|" | cut -d\| -f2)
localid=$(echo " |$LOC_TYPE|$LOCATION_ID|$WAREHOUSE|" | cut -d\| -f3)
wareH=$(echo " |$LOC_TYPE|$LOCATION_ID|$WAREHOUSE|" | cut -d\| -f4)
echo "localty=$localty localid=$localid wareH=$wareH" >> ttt.log
result -->>> localty= localid= wareH=NRT
thank you
sauron
April 13, 2009, 6:51am
4
Hi ,
where do you assign a value to:
$LOC_TYPE
$LOCATION_ID
$WAREHOUSE
? i'm a bit confused
ryanW
April 13, 2009, 6:58am
5
those variable get from select statement.
select LOC_TYPE, LOCATION_ID, WAREHOUSE from JEALOCATION where
LOCATION_ID="NTTR"
LOC_TYPE,LOCATION_ID,WAREHOUSE
sauron
April 13, 2009, 8:04am
6
Hi,
i don't understand why you need to use:
localty=$(echo " |$LOC_TYPE|$LOCATION_ID|$WAREHOUSE|" | cut -d\| -f2)
when you can use
localty=$(echo "$LOC_TYPE")
etc
ryanW
April 13, 2009, 8:27am
7
Hi Sauron,
for select statement...
data_type_SQL=$($CONNECT cat <<-__EOF__
SET NOCOUNT ON
select LOC_TYPE, WAREHOUSE, LOCATION_ID from JEALOCATION where
LOCATION_ID="$data_LocID_SQL"
got value inside in each LOC_TYPE, WAREHOUSE, LOCATION_ID from data_type_SQL variable..
but when i try to assign each variable... those 3 is empty..
localty=$(echo "$LOC_TYPE")
wareH=$(echo "$WAREHOUSE")
localid=$(echo "$LOCATION_ID")
here is the result after i debug
****************************************
data_type_SQL=|G |NRT |NRTW |
localty=
wareH=
localid=
***************************************
Can u help me?
Thank you
sauron
April 13, 2009, 8:37am
8
So,
data_type_SQL="|G |NRT |NRTW |" put double quotas
so you'll got
echo $data_type_SQL
|G |NRT |NRTW |
localty=$(echo $data_type_SQL | cut -d\| -f2| sed -e 's/|//g')
# echo $localty
G
whareH=$(echo $data_type_SQL | cut -d\| -f3| sed -e 's/|//g')
# echo $whareH
NRT
localid=$(echo $data_type_SQL | cut -d\| -f4| sed -e 's/|//g')
# echo $localid
NRTW
this is working in my shell, if i understood
Hope it helps
Bye
ryanW
April 13, 2009, 8:44am
9
Yes.... it is working..
Thank you so... sosososososo much..!!!
i will work hard!!!
terima kasih...
Try:
### Remove hyphen ###
$CONNECT cat << __EOF__ |
SET NOCOUNT ON
select LOC_TYPE, WAREHOUSE, LOCATION_ID from JEALOCATION where
LOCATION_ID="$data_LocID_SQL"
__EOF__
read LOC_TYPE WAREHOUSE LOCATION_ID
got value inside in each LOC_TYPE, WAREHOUSE, LOCATION_ID from data_type_SQL variable..
but when i try to assign each variable... those 3 is empty..
localty=$(echo "$LOC_TYPE")
wareH=$(echo "$WAREHOUSE")
localid=$(echo "$LOCATION_ID")
First of all, you have not declared any variables name LOC_TYPE, WAREHOUSE.. etc...
Those are column names from your SQL and are not automatically exported with
their values in tact to the shell.
Secondly, if they were, you could make the assignments like this, but it would
be unnecessary and better practice just to leave them as their column names.
localty=$LOC_TYPE
wareH=$WAREHOUSE
localid=$LOCATION_ID