How to get range of records from TEMP TABLE with alphanumeric column? - progress-4gl

I have a TEMP TABLE with an alphanumeric column and I want to get the range of records on basis of 2 filters.
**Filters:** Begin filter and End filter.
**For Example: Column data:**
A123
A145
B002
B234
C095
C456
D001
D345
Begin filter -> A14 and End filter -> D12
**Expected Result:**
A145
B002
B234
C095
C456
D001
Is there any way to do it?
Thanks in Advance!

Do you mean something like this?
FOR EACH ttName
WHERE ttName.FieldName >= "A14" and ttName.FieldName <= "D12"
NO-LOCK:
/* do stuff */
END.

Related

Repeat the value from left table if date from right table falls between start date and end date

I would like to join my two tables on [Group] and [YearMonth] Dates. Where [YRMO_NB] from Table 2 falls between [ENR_START] AND [ENR_END] from Table 1 then repeat the value of column [PHASE] for each related row, just like the second picture last column = [PHASE] and leaves unmatched rows blank.
I did this which only gives me exact matches:
ON A.GROUP = PHASE.GROUP
AND A.YRMO_NB = PHASE.ENR_START
Table 1
Table 2
Is there an easy way to do this ?
Thank You!
I figured it out
ON A.GROUP = PHASE.GROUP
AND A.YRMO_NB >= PHASE.ENR_START
and A.YRMO_NB <= PHASE.ENR_END

Does my Postgresl column contain only digits?

Is there a way to check if a character varying type column contains only digits or null values with Postgresql?
Maybe something like (this syntax is incorrect):
SELECT *
FROM mytable
ORDER BY
CASE WHEN mycol ~ '^[0-9\.]+$' THEN 1 ELSE 0 END
LIMIT 1
I'm expecting TRUE or FALSE as final result for the whole column.
If you want to to know if the values in all rows are digits, you can use
select not exists (select *
from mytable
where not (mycol ~ '^[0-9\.]+$'))
Online example
To get Nulls use COALESCE(mycol, 1) -- will return 1 if the value in mycol is NULL.
For checking numerics you could use regex LIKE'^[0-9]*' it wont detect decimal dots (dont know if your data have decimals)
BR!

update statement with replace in postgresql

I have table having below records
Sno A
- --
1 spoo74399p
2 spoo75399p
I want to update the above records by replacing oo (alphabet 'o') by empty after sp
afte
Required OUTPUT
----------------
Sno A
1 sp74399p
2 sp75399p
UPDATE my_table
SET A = REPLACE(A, 'spoo', 'sp');
This would update all the records.
To clarify a bit, this would find any instances of "spoo" and replace them with "sp". The end result is that any "oo" right after "sp" would be deleted.

Trying to get rid of unwanted records in query

I have the following query
Select * from Common.dbo.Zip4Lookup where
zipcode='76033' and
StreetName='PO BOX' and
'704' between AddressLow and AddressHigh and
(OddEven='B' or OddEven = 'E')
The AddressLow and AddressHigh columns are varchar(10) fields.
The records returned are
AddressLow AddressHigh
------------ ------------
1 79
701 711
The second is the desired record How do I get rid of the first record.
The problem is that SQL is using a string compare instead of a numeric compare. This is because AddressLow/High are varchar and not int.
As long as AddressLow/High contain numbers, this should work:
Select * from Common.dbo.Zip4Lookup where
zipcode='76033' and
StreetName='PO BOX' and
704 between
CAST(AddressLow as INT) and
CAST(AddressHigh as INT) and
(OddEven='B' or OddEven = 'E')
The problem is that your condition fits to the first record in 7 on the beginning of the 79 because it's the string value. The easist way is IMHO change the data type to some numeric one.

How can we use prefix as zero in SQL?

How can we use zero's in prefix of the number column feedback_refno like
select #refno = '0001'
i need to insert this value into that column feedback_refno but it is inserting like 1 only..but i need those prefix before those 1
I have tried like this
declare #refno int
select max(feedback_refno)+1 from EDK_Customer_Feedback(nolock)
if not exists(select feedback_refno from EDK_Customer_Feedback(nolock))
Begin
select #refno = '0001'
end
else
Begin
select #refno
End
insert into EDK_Customer_Feedback values(#refno)
I need the result like 0002 then 0003 like that but it is giving like 2 then 3..
Any suggestion?
try this
SELECT RIGHT('000'+ CONVERT(varchar,feedback_refno),4) AS NUM FROM EDK_Customer_Feedback;
#refnois of type int, so leading zeros wont work. If you change it to varchar(4) you can use these two answers:
In SQL Server 2000 how do you add 0's to beginning of number to fill nchar(n)
In SQL Server 2000 how do you add {n} number of 0's to a nchar(n)?