Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Read a temp table and update from another select

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-12-08 : 16:13:03
In my proc I have created a temp table:

create table	#JDE_EqmHrsDetailTable
( jde_job_date datetime,
jde_cost_code nvarchar(15),
jde_detail_hrs decimal(8,2),
jde_eqm_id int,
jde_eqm_name nvarchar(12)
)


I am populating the temp table (1st 4 fields) with a call to a proc on a db2/400:

insert into #JDE_EqmHrsDetailTable(jde_job_date, jde_cost_code, jde_detail_hrs, jde_eqm_id)
Exec ('Call QGPL.get_eqmdet(?,?,?,?)', @JobNumber1, @ItemNumber1, @JdeDateFrom, @JdeDateTo) AT AS400SRV_MSDASQL


This works fine. Here is where I need to go and I am unceratin how to do this:

I need update the last field in the temp table (jde_eqm_name). To do this I have to read the temp table and use the 4th field (jde_eqm_id) as a parm to call another proc on db2/400. I have created the proc

Exec ('Call QGPL.get_itmmst (?)', jde_eqm_id) AT AS400SRV_MSDASQL


The call to the proc (on db2/400) will return jde_eqm_name

create procedure get_itmmst                                 
(in @jde_eqm_id int)
result set 1
language sql
reads sql data
begin
declare c1 scroll cursor with return for
select faapid as jde_eqm_name
from vgiprddta/f1201la where fanumb = @jde_eqm_id
group by faapid;
open c1;
end;




visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-09 : 02:32:19
Make the db2 procedure a function. in this way, you can simply do like below

UPDATE jde_eqm_name 
SET QGPL.get_itmmst(jde_eqm_id)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-09 : 02:33:43
See here for help on UDF

http://www.sqlteam.com/article/user-defined-functions
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-09 : 02:35:49
Another option is to use OPENROWSET

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-12-09 : 08:35:40
Thank you, got it working.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-09 : 13:14:17
Welcome
Go to Top of Page
   

- Advertisement -