dbTalk Databases Forums  

Can this be done with a Query Only either QBE or Local SQL ?

comp.databases.paradox comp.databases.paradox


Discuss Can this be done with a Query Only either QBE or Local SQL ? in the comp.databases.paradox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Leslie Milburn
 
Posts: n/a

Default Can this be done with a Query Only either QBE or Local SQL ? - 06-26-2003 , 06:30 AM






Hi All,

Target Database is Paradox.
As a result of a query I end up with an Answer Table with the Column
"CLIENT_ID".
What I need to do is to add new records to another Table which has the
following format:

UNIQUE_ID A14
CLIENT_ID A14
CAMPAIGN_ID A14
Status A20

CLIENT_ID is to be populated from the Answer Table.
CAMPAIGN_ID is constant for all the records that will be inserted, say
'XYS12345'.
Status is contant and must be set to 'Send Mail'.

The problem is the UNIQUE_ID field. This is in the format of a dbid with the
record number appended. So for example the first record could be xywr1, the
second xywr2, the third xywr3 and so on. What I need to do is to somehow
generate this ID as part of the query. I know the next available value at
the time of executing the query but I have no idea how to use this as part
of the query when I insert the records.

The number of records to insert could range from 1 to 10000, so doing this
via a query leaves direct calls to the BDE for dead, we would probably be
measuring seconds against minutes.

So my question is can I do this by a query or even a series of queries, if
so how ? I prefer QBE but Local SQL is fine as well.
Thanks for any help
Leslie.






Reply With Quote
  #2  
Old   
Steven Green
 
Posts: n/a

Default Re: Can this be done with a Query Only either QBE or Local SQL ? - 06-26-2003 , 07:30 AM






Leslie Milburn wrote:

Quote:
So my question is can I do this by a query or even a series of queries, if so
how ? I prefer QBE but Local SQL is fine as well.
same answer as Dennis gave.. you can't do it in a query.. from that angle, you
have to do it by scanning the table.. unless Larry has an angle for SQL (which I
really don't expect), that's the only way to do it..


--

Steve Green - Diamond Software Group, Inc - Waldorf Maryland USA
Corel CTech Paradox - http://www.diamondsg.com - Support/Downloads/Links
---------------------------------------------------------------------------------

Do you need a Sanity Check? http://www.diamondsg.com/sanity.htm
Upgrade/Downgrade versions? http://www.diamondsg.com/upgrade.htm
-------------------------------------------------------------------------




Reply With Quote
  #3  
Old   
Larry DiGiovanni
 
Posts: n/a

Default Re: Can this be done with a Query Only either QBE or Local SQL ? - 06-26-2003 , 08:12 AM



I can think of one way. Create an intermediate table with the other 3
columns, and a UNIQUE_ID (or whatever you want to call it) as an autoinc.
Insert the other values via a query. Then in a second query to your
actual table, you can do scalar calcs on the autoinc value for each row,
which you can treat like a record number.

At the end of query 1 you have

UNIQUE_ID CLIENT_ID CAMPAIGN_ID Status
1 AAAAA XYS12345 Send Mail
2 AAAAB XYS12345 Send Mail
3 AAAAC XYS12345 Send Mail
....
100000 ZZZZZ XYS12345 Send Mail

In a second insert query to your destination, you can perform whatever
fixed calc you want on UNIQUE_ID to give it the formatting you want - add
a minimum for it, append text, whatever.

--
Larry DiGiovanni
Digico, Inc
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources




Reply With Quote
  #4  
Old   
Leslie Milburn
 
Posts: n/a

Default Re: Can this be done with a Query Only either QBE or Local SQL ? - 06-26-2003 , 08:15 AM



Hi Larry,

This is a very smart solution indeed. However, my ignorance of QBE syntax
means I do not have a clue how to force the formatting I require on the
second query.

Keeping it simple for me, lets say I have done the first query and generated
the intermediate table as per your example. How would I then transfer the
data over and say add the intermediate UNIQUE_ID (1....10000) to the
starting value of 'xyz1234'.

Thanks
Leslie.


"Larry DiGiovanni" <larryd (AT) digicoinc (DOT) com> wrote

Quote:
I can think of one way. Create an intermediate table with the other 3
columns, and a UNIQUE_ID (or whatever you want to call it) as an autoinc.
Insert the other values via a query. Then in a second query to your
actual table, you can do scalar calcs on the autoinc value for each row,
which you can treat like a record number.

At the end of query 1 you have

UNIQUE_ID CLIENT_ID CAMPAIGN_ID Status
1 AAAAA XYS12345 Send Mail
2 AAAAB XYS12345 Send Mail
3 AAAAC XYS12345 Send Mail
...
100000 ZZZZZ XYS12345 Send Mail

In a second insert query to your destination, you can perform whatever
fixed calc you want on UNIQUE_ID to give it the formatting you want - add
a minimum for it, append text, whatever.

--
Larry DiGiovanni
Digico, Inc
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources






Reply With Quote
  #5  
Old   
Leslie Milburn
 
Posts: n/a

Default Re: Can this be done with a Query Only either QBE or Local SQL ? - 06-26-2003 , 08:41 AM



Thanks Larry,

FYI: 1234 is a numeric which is incremented.

I'll give this a go, hopefully Local SQL can do the job - I've always found
it difficult to use compared to other SQL dialects.

Thanks again and also to the others who replied. I'll let you know how it
went tomorrow (its midnight here in Australia).
Leslie

"Larry DiGiovanni" <larryd (AT) digicoinc (DOT) com> wrote

Quote:
Leslie Milburn wrote:

Keeping it simple for me, lets say I have done the first query and
generated the intermediate table as per your example. How would I
then transfer the data over and say add the intermediate UNIQUE_ID
(1....10000) to the starting value of 'xyz1234'.

Is 1234 is to be treated as numeric

xyz1235
xyz1236
...
xyz11234

or as an alphanumeric seed:

xyz12341
xyz12342
...
xyz123410000

Either way, I'd use SQL. Not sure if QBE will do the implicit typecasting
you'd need.

SELECT 'xyz' || CAST(1234 + unique_id as CHAR(6)) as unique_id,
client_id, campaign_id, Status
FROM answer

Will give you an answer table with 1234 treated as a numeric seed. Move
1234 into the prefix string xyz if you want it the other way.

I forget if that'll leave trailing spaces (char(6)) or not. If it does
and you don't want them:

SELECT 'xyz' || TRIM(TRAILING ' ' FROM CAST(1234 + unique_id as CHAR(6)))
as unique_id,
client_id, campaign_id, Status
FROM answer

--
Larry DiGiovanni
Digico, Inc
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources






Reply With Quote
  #6  
Old   
Larry DiGiovanni
 
Posts: n/a

Default Re: Can this be done with a Query Only either QBE or Local SQL ? - 06-26-2003 , 09:11 AM



Leslie Milburn wrote:

Quote:
Thanks again and also to the others who replied. I'll let you know how
it
went tomorrow (its midnight here in Australia).
Midnight is prime programming time. Goodnight, slacker <g>.

--
Larry DiGiovanni
Digico, Inc
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources





Reply With Quote
  #7  
Old   
Larry DiGiovanni
 
Posts: n/a

Default Re: Can this be done with a Query Only either QBE or Local SQL ? - 06-26-2003 , 09:14 AM



Mike Irwin [CTech] wrote:

Quote:
How come you get to the neat answers before I read the NG ? It's
just not fair !
Maybe if you roll outta bed earlier than 10am. Hmmm?



--
Larry DiGiovanni
Digico, Inc
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources





Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.