473,734 Members | 2,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select from a sequence and from a table in the same statement

The following statement doesn't work and I need a tip.

Here is a draft:

This selects data from the z table.
And fetches the next value for r_id_seq and creates a table named b.
select z.r_name,b.r_id from
(select r_name from z.r_lookup where r_id=821 ) z
right outer join values
(select nextval for r_id_seq from sysibm.sysdummy 1) as b(r_id)

There is nothing to select on in a ON clause, there is a single tuple
in z and in b, and both are returned.

Here is where I'm going with this:

insert into new_table (r_name,r_id) values (

select z.r_name,b.r_id from
(select r_name from z.r_lookup where r_id=821 ) z
right outer join values
(select nextval for r_id_seq from sysibm.sysdummy 1) as b(r_id)

)

Jul 12 '07 #1
2 2028
gi************* ******@yahoo.co m wrote:
insert into new_table (r_name,r_id) values (

select z.r_name,b.r_id from
(select r_name from z.r_lookup where r_id=821 ) z
right outer join values
(select nextval for r_id_seq from sysibm.sysdummy 1) as b(r_id)

)
INSERT INTO news_table(r_na me,r_id)
SELECT r_name, next value for r_id_seq from z.r_lookup where r_id=821

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jul 12 '07 #2
Works great.

Thanks Serge.
Jul 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
46647
by: Andrew Baker | last post by:
What is the best way to lock an individual row in the following scenerio: --TODO - LOCK THIS ROW -- Return the next id SELECT next_id INTO next_id_out FROM owner.my_id_table WHERE app_id = app_id_in;
7
2659
by: php newbie | last post by:
I am trying to copy data from one table to another, and in the process add a sequence number to copied rows. I have looked at the IDENTITY function when creating tables, and essentially this is the behavior I am trying to duplicate. However, my question is if I can do this with the SELECT INTO statement as well. I have tried a few variations and it does not seem to work: SELECT seq_number = identity(10),
1
1774
by: Gaz | last post by:
I'm sure this is an obvious question but much of SQL is new to me. I have a stored procedure and I want to use the results of a select statement elsewhere in the stored prcedure. The select statement will return at most one record and only one column, here's an example : select top 1 Sequence from MyTable where ParentId=4 and Sequence > 200 order by sequence
3
7671
by: joseph speigle | last post by:
hello list, I want to do something like the following: address=# @var = select max(id) from passwd; ERROR: parser: parse error at or near "@" at character 1 address=# var = select max(id) from passwd; ERROR: parser: parse error at or near "var" at character 1 address=# :var = select max(id) from passwd; ERROR: parser: parse error at or near ":" at character 1
1
3687
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into "access_log", the referential integrity triggers generate these queries: SELECT 1 FROM ONLY "public"."application_type" x
5
4536
by: Antanas | last post by:
Hi folks. I need unique sequence object generated for each row returned form select statement. Here is my ADDID() UDF: CREATE FUNCTION DB2ADMIN.ADDID() RETURNS CHAR(6) NOT DETERMINISTIC F1: BEGIN ATOMIC DECLARE ID CHAR(6); SET ID = 'BB' CONCAT (substr(char(cast(NEXT VALUE for DB2ADMIN.SEQUENCEID as decimal(4, 0))), 1, 4)) ;
19
8378
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without FOR UPDATE, it is fine and no error. I also tried Set objRs = objConn.Execute("SELECT * FROM EMP UPDATE OF EMPNO"), but it still couldn't help. any ideas? I tried to search in the web but couldn't find similar
6
3394
by: Apaxe | last post by:
In the database i have a table with this information: key_id =1 key_desc =43+34+22+12 I want sum the values in key_desc. Something like: SELECT key_desc FROM table But the result of the select was "111" and not "43+34+22+12".
0
1304
by: bharadwajrv | last post by:
I have created the sequence in the DB2 and i need to query what will be the next possible value for this sequence... Ex. Select NEXT VALUE for schema_name.sequence_name but above sql statement results in error message... I need to send next_value of sequence to application so that, application will make use to populate the other related tables.... ( we have a parent-child relationship in the database and PK of the master table needs to...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.