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 > first 4 number from BIGINT filed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-14-08, 08:02
deepsfriend4u deepsfriend4u is offline
Registered User
 
Join Date: Jul 2008
Posts: 4
first 4 number from BIGINT filed

Hello all,

I have 1 table in that 3 fields, and 3rd filed is INTIME and data_type is BIGINT

i am fire one query as follows:
select INTIME from table_name where ....

then Output =102390

But I want Output is 1023 i.e. only first 4 number

thanks in Advanced.

with warm Regards
Deepak
--;--;<@
Reply With Quote
  #2 (permalink)  
Old 07-14-08, 09:09
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
substr(char(intime),1,4)

Andy
Reply With Quote
  #3 (permalink)  
Old 07-14-08, 09:12
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Or int(intime/100)
Reply With Quote
  #4 (permalink)  
Old 07-14-08, 09:13
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Don't even need the int(), really.
Reply With Quote
  #5 (permalink)  
Old 07-14-08, 09:16
deepsfriend4u deepsfriend4u is offline
Registered User
 
Join Date: Jul 2008
Posts: 4
Thanks

Thanks Very much
Reply With Quote
  #6 (permalink)  
Old 07-14-08, 09:17
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Quote:
Originally Posted by n_i
Or int(intime/100)
This will only work if the bigint is between 100000 and 999999. Any other numbers it will fail.

Andy
Reply With Quote
  #7 (permalink)  
Old 07-14-08, 10:32
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
True, but we're not dealing with just any numbers here: these are time values represented as numbers, if I understand the OP correctly, so the values will always be between 000000 and 235959
Reply With Quote
  #8 (permalink)  
Old 07-14-08, 10:43
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Quote:
Originally Posted by n_i
True, but we're not dealing with just any numbers here: these are time values represented as numbers, if I understand the OP correctly, so the values will always be between 000000 and 235959
If this is true, then it will fail for all times prior to 10 AM. This is 41% of the day.

Andy
Reply With Quote
  #9 (permalink)  
Old 07-14-08, 11:14
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Well, I might have misunderstood the problem. I assumed that the value in INTIME represents time in the format of HHMMSS, and Mr. Deepak wants to extract just hours and minutes. If that's the case my approach would work correctly for any value.

However, if the time representation is somehow different, the SUBSTR() would be the right approach.
Reply With Quote
  #10 (permalink)  
Old 07-14-08, 11:21
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The values are stored in a bigint. So 1 AM would be 10000, not 010000 since there are no "leading zeros" on integer data types. But if the values in the field are indead supposed to be time values in the format of hhmmss and the OP does want just the hhmm portion, then dividing by 100 would work.

Andy
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