midrange.com code scratchpad
Name:
SQL queries and file structure
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
07/04/2022 06:32:27 pm
IP:
Logged
Description:
Hi,

Please find SQL Queries ( on file1) and on view V1 like below:-
Code:
  1. 1. SQL-if my sql query is like  this :-  ' SELECT * FROM LIB1/file1  where
  2. ((field1* 1000000) + ( field2*10000) + (field3*100) + field4)  between
  3. '20210601'  and  '20210607'
  4.  
  5. 2. View:- CREATE VIEW LIB1/V1 AS ( SELECT DIGITS(DEC(FIELD1*1000000)  +
  6. (FIELD2*10000)  +  (FIELD3*100)   +  FIELD4,8,0)) AS MYDATE , A.*  FROM
  7. LIB1/FILE1  A)
  8.  
  9. 3.  select count(*) from lib1/v1 where MYDATE  between '20210601'  and  '20210607'  
  10.  
  11.  
  12.  
  13. 4)  select count(*) from lib1/v1 where MYDATE  between 20210601  and  20210607  
  14.  
  15.  
  16.  
  17. Output :-  1.  = 2.  for record count.
  18.            3.  = 4.  for record count.
  19.  
  20. but record count for (1. and 2. SQL Queries ( on file1) was too less than  compared to record count for (3. and 4. (SQL queries for record count for view (V1)  )
  21.  
  22.  
  23. File1(PF) structure:-
  24.  
  25.  
  26. field         type                    length         scale     
  27. field1         decimal                     6          
  28. field2        character                     9          
  29. field3        decimal                     7          
  30. field4        decimal                     2                              CC
  31. field5        decimal                     2                              YY
  32. field6        decimal                     2                              MM
  33. field7        decimal                     2                              DD
  34. field8        character                     7          
  35. field9        character                    30          
  36. field10        character                     3          
  37. field11        character                     1          
  38. field12        character                     1           
  39. field13        decimal                     2                              MM
  40. field14        decimal                     2                              DD
  41. field15        decimal                     2                              CC
  42. field16        decimal                     2                              YY
  43. field17        decimal                     2                              MM
  44. field18        decimal                     2                              DD
  45. field19        decimal                     2                              CC
  46. field20        decimal                     2                              YY
  47. field21        decimal                     2                              MM
  48. field22        decimal                     2                              DD
  49. field23        decimal                     2                              CC
  50. field24        decimal                     2                              YY
  51. field25        character                    10          
  52. field26        character                    10          
  53. field27        character                     6          
  54.  
  55.  
  56. *****************************************************************************************************************
  57.  
  58. Above structure of file1 is obtatined by joining some files like below:-
  59.  
  60. select a.fld1,b.fld2,a.fld2,a.fld3,a.fld4,a.fld5,a.fld6, from libx/filea1  a leftjoin  libx/fileb1 b on digits(a.fld1) = trim(b.fld2) and b.fld1  like '%ABCD%'
  61.  
  62. then above sql query gives me filea2 in my library lib1.
  63.  
  64. then using this filea2  i create another SQL query like below:-
  65.  
  66. select * from lib1/filea2  A left join  libx/filea3   B  on  digits(a.fld2)  = trim(b.filea3)
  67.  
  68. then i get finally the file file1 - for which i shared above sql queries 1.,2.,3.,4. ( on file1) and views (V1) 
  69.  
  70. And above SQL queries on file1(1,2,3,4) and view (v1) go executed without any error( i did not find any typo errors while executing them).
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css