If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > substring in sqls

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-09, 04:47
sandhya.karanam sandhya.karanam is offline
Registered User
 
Join Date: Nov 2009
Posts: 5
substring in sqls

Hi,

I want to use the host vairables in the SUBSTR function in an SQL. When i tried to do it, it is giving me sqlcode = -171.

Can we use the host variables in an sql for the SUBSTR function. This is in COBOL400.

My sql requirement is :

select * from temtbl
where substr(data, :ws_len1, :ws_len2)

the variables are declared as follows:

ws_len1 pic s9(03).
ws_len2 pic s9(03).

Please let me know as early as possible..

Thank you,
Sandhya.
Reply With Quote
  #2 (permalink)  
Old 12-09-09, 05:53
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Do not know COBOL400. As a mainframe guy my Pavlov reaction would be:
Code:
ws_len1 pic s9(04) comp.
ws_len2 pic s9(04) comp.
Why don't you give it a try.
Reply With Quote
  #3 (permalink)  
Old 12-09-09, 05:55
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
You can use hostvariables with SUBSTR(field,startpos,length).
startpos and length must be of type INTEGER
( i believe, it's comp-3 in COBOL)

use of LIKE instead of SUBSTR is more efficient in most cases.
Reply With Quote
  #4 (permalink)  
Old 12-09-09, 08:05
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Quote:
Originally Posted by umayer View Post
( i believe, it's comp-3 in COBOL)
Wrong!
Code:
pic s9(4)  comp = halfword  binary integer
pic s9(9)  comp = fullword  binary integer
pic s9(18) comp = doubleword binary interger
Reply With Quote
  #5 (permalink)  
Old 12-09-09, 22:50
sandhya.karanam sandhya.karanam is offline
Registered User
 
Join Date: Nov 2009
Posts: 5
i tried using comp as well as comp-3 but still i am getting the sqlcode -171, it says the value or data type or length of the argument in function not valid
Reply With Quote
  #6 (permalink)  
Old 12-09-09, 23:21
DB2Plus DB2Plus is offline
Registered User
 
Join Date: Jul 2009
Posts: 150
Smile

Quote:
Originally Posted by sandhya.karanam View Post
i tried using comp as well as comp-3 but still i am getting the sqlcode -171, it says the value or data type or length of the argument in function not valid
Quote:
Working storage section.
01 start pic s9(4) binary.
01 len pic s9(4) binary.
01 substring pic x(777) value spaces.
01 length-of-string pic s9(4) binary.
Code:
Procedure division.

exec sql Select substr(string, :start, :len) 
        into :substring from temtbl
end-exec
If sqlcode < 0 
   display 'sqlcode = ' sqlcode 'len = '  len ' start = ' start
   exec sql Select length(string) 
              into :length-of-string  from temtbl
       end-exec   
   display 'length of string = ' length-of-string  
end-if
Quote:
1. start > 0 and start <= length(string)
2. len >= 0 and len <= length(string)
3. start + len <= length(string) + 1
4. You can omit len
Kara

Last edited by DB2Plus; 12-09-09 at 23:44.
Reply With Quote
  #7 (permalink)  
Old 12-10-09, 10:26
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Question What does it mean

Quote:
Originally Posted by sandhya.karanam View Post
Hi,

I want to use the host vairables in the SUBSTR function in an SQL. When i tried to do it, it is giving me sqlcode = -171.

Can we use the host variables in an sql for the SUBSTR function. This is in COBOL400.

My sql requirement is :

select * from temtbl
where substr(data, :ws_len1, :ws_len2)

the variables are declared as follows:

ws_len1 pic s9(03).
ws_len2 pic s9(03).

Please let me know as early as possible..

Thank you,
Sandhya.
ws-len1 comp pic s9(04).
ws-len2 comp pic s9(04).

Also I didn't understand what does it mean ?

Code:
select * from temtbl
where substr(data, :ws_len1, :ws_len2)
Maybe

Code:
select * from temtbl
where substr(data, :ws-len1, :ws-len2) = 'something'
Lenny
Reply With Quote
  #8 (permalink)  
Old 12-11-09, 00:12
sandhya.karanam sandhya.karanam is offline
Registered User
 
Join Date: Nov 2009
Posts: 5
hi lenny, yeah i missed it...

wat u have given is right...

i could see that we are not able to use the host variables in a substr function, rather i used a dynamic sql and it worked.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On