× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Jerry,

In SQL single quotes go around character constants. They are not needed for numeric data.

Also you don't need DIGITS, because that converts numeric to character. You want to stick with numeric.


Here is a *final* proof of concept for you to digest. All this SQL runs successfully and produces the expected results of 3 records from both the file and the view.

If your results from the real data don't match, then you have made an error somewhere,but since we can't see the real code, there is no more help possible.



-- drop existing table and view
drop table lennons1.file1
;

-- create a test table
create or replace table lennons1.file1 (
field1 decimal (2 , 0),
field2 decimal (2 , 0),
field3 decimal (2 , 0),
field4 decimal (2 , 0),
afield char(20)
)
;

-- create some test data
insert into lennons1.file1
values
(19,98,12,25, 'rcd 1'),
(00,01,12,31, 'rcd 2'),
(20,21,06,01, 'rcd 3*'),
(20,21,06,05, 'rcd 4*'),
(20,21,06,07, 'rcd 5*'),
(20,21,06,08, 'rcd 6'),
(20,21,06,31, 'rcd 7'),
(20,21,12,25, 'rcd 8'),
(99,99,12,31, 'rcd 9')
;

-- Review created data
select * from lennons1.file1
;
-- Create a view
CREATE or replace VIEW lennons1.V1 AS (
SELECT
decimal(
(FIELD1*1000000) +
(FIELD2*10000) +
(FIELD3*100) +
FIELD4
,8,0) as mydate
,A.*
FROM lennons1.FILE1 A
)
;

-- Prove the view works
select * from lennons1.V1
;

-- Count rows in view
select count(*) from lennons1.V1
;

-- select from the view the desired date range
select * from lennons1.V1
where mydate between 20210601 and 20210607
;

-- select from the file the desired date range
select * from lennons1.file1
where (FIELD1*1000000) +
(FIELD2*10000) +
(FIELD3*100) +
FIELD4
between 20210601 and 20210607;



On 7/4/2022 3:50 PM, jerry ven wrote:
Hi,

I just meant there is difference of too many records for below two SQL
queries:-

SELECT * FROM LIB1/file1 wherE ((field1* 1000000) + ( field2*10000) +
(field3*100) + field4) betweeN
'20210601' and '20210607'


select count(*) from lib1/v1 where MYDATE between '20210601' and '20210607'


And it does not matter whether i keep single quotes around these date
numbers or not , difference of many records remain always.


Thanks


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.