Unix Technical Forum

Call a View over SQL (DB2 UDB V8.1.6)

This is a discussion on Call a View over SQL (DB2 UDB V8.1.6) within the DB2 forums, part of the Database Server Software category; --> Hi Newsgroup. I need to call a view over an SQL statement. The SQL statement makes an update at ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 05:11 AM
Fresh80@gmx.de
 
Posts: n/a
Default Call a View over SQL (DB2 UDB V8.1.6)

Hi Newsgroup.

I need to call a view over an SQL statement.
The SQL statement makes an update at a table and needs the view in the
where part of the statement.
Example:

UPDATE EK_USER.ARTIKELGRUNDDATEN_TEST ARTIKELGRUNDDATEN_TEST
SET NEU = '1'
where ARTIKELGRUNDDATEN_TEST.ARTNR = VIEW_ARTIKELGRUNDDATEN.ARTNR
and
ARTIKELGRUNDDATEN_TEST.HARTNR = VIEW_ARTIKELGRUNDDATEN.HARTNR



Can anybody help me?

Thanks,

Sascha.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 05:11 AM
Knut Stolze
 
Posts: n/a
Default Re: Call a View over SQL (DB2 UDB V8.1.6)

Fresh80@gmx.de wrote:

> Hi Newsgroup.
>
> I need to call a view over an SQL statement.
> The SQL statement makes an update at a table and needs the view in the
> where part of the statement.
> Example:
>
> UPDATE EK_USER.ARTIKELGRUNDDATEN_TEST ARTIKELGRUNDDATEN_TEST
> SET NEU = '1'
> where ARTIKELGRUNDDATEN_TEST.ARTNR = VIEW_ARTIKELGRUNDDATEN.ARTNR
> and
> ARTIKELGRUNDDATEN_TEST.HARTNR = VIEW_ARTIKELGRUNDDATEN.HARTNR


Just query the view in a sub-select inside the WHERE clause.

--
Knut Stolze
Information Integration Development
IBM Germany / University of Jena
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 05:11 AM
Serge Rielau
 
Posts: n/a
Default Re: Call a View over SQL (DB2 UDB V8.1.6)

Fresh80@gmx.de wrote:
> Hi Newsgroup.
>
> I need to call a view over an SQL statement.
> The SQL statement makes an update at a table and needs the view in the
> where part of the statement.
> Example:
>
> UPDATE EK_USER.ARTIKELGRUNDDATEN_TEST ARTIKELGRUNDDATEN_TEST
> SET NEU = '1'
> where ARTIKELGRUNDDATEN_TEST.ARTNR = VIEW_ARTIKELGRUNDDATEN.ARTNR
> and
> ARTIKELGRUNDDATEN_TEST.HARTNR = VIEW_ARTIKELGRUNDDATEN.HARTNR

I'm not clear what this has to do with teh fact that you refer to a
view... anyway:
UPDATE T SET T.c1 = 1 WHERE EXISTS(SELECT 1 FROM S WHERE T.pk = S.pk)

If you need S in the SET clause as well I recommend the MERGE statement:

MERGE INTO T USING S ON T.pk = S.pk
WHEN MATCHED THEN UPDATE SET T.c1 = S.c1

Cheers
Serge


--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:54 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com