If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Sql server to Db2 -- select top 100 percent

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-23-10, 07:22
prashanth.bsp prashanth.bsp is offline
Registered User
 
Join Date: Apr 2010
Posts: 3
Sql server to Db2 -- select top 100 percent

Hi friends,

Could any one help me out on migrating below query to Db2?..


create view ipm_booking_view_pass as
select top 100 percent b.*, p.passenger_unique_key, p.pass_fname, p.pass_lname
from ipm_booking_view b left outer join ipm_booking_passengers p on b.oid = p.oid
order by b.store_id, b.booking_id, p.passenger_unique_key
GO

Note:- I am using DB2 9.7

Thanks
Reply With Quote
  #2 (permalink)  
Old 04-23-10, 08:14
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
top 100 percent <> All?
Reply With Quote
  #3 (permalink)  
Old 04-23-10, 08:48
prashanth.bsp prashanth.bsp is offline
Registered User
 
Join Date: Apr 2010
Posts: 3
Hi,
Yes, i need it like the way it works in sql sever
thanks
Reply With Quote
  #4 (permalink)  
Old 04-23-10, 09:04
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
in that case wouldn't you just remove the TOP 100 percent?
Dave
Reply With Quote
  #5 (permalink)  
Old 04-23-10, 09:12
prashanth.bsp prashanth.bsp is offline
Registered User
 
Join Date: Apr 2010
Posts: 3
Hi Dave,

I got error as below after removing top 100 percent.

create view ipm_booking_view_pass as select b.*, p.passenger_unique_key, p.pass_fname, p.pass_lname from ipm_booking_view b left outer join ipm_booking_passengers p on b.oid = p.oid order by b.store_id, b.booking_id, p.passenger_unique_key
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL20211N The specification ORDER BY or FETCH FIRST n ROWS ONLY is invalid.
SQLSTATE=428FJ

SQL20211N The specification ORDER BY or FETCH FIRST n ROWS ONLY is invalid.


Explanation:

An ORDER BY or FETCH FIRST n ROWS ONLY is not allowed in:
* the outer fullselect of a view
* the outer fullselect in the RETURN statement of an SQL Table function
* a materialized query table definition
* a subselect which is not enclosed in parenthesis

User response:

In case of:

subselect
Enclose the subselect including the ORDER BY or FETCH FIRST n
ROWS ONLY in parenthesis.

FETCH FIRST n ROWS ONLY
Use the ROW_NUMBER() OVER() clause in conjunction with a
predicate in the where clause. Example:
SELECT name FROM
(SELECT
ROW_NUMBER() OVER() AS m, name
FROM emp
) AS e
WHERE m < 10


ORDER BY Use ORDER BY in the query using the view, the materialized
query table, or the SQL table function instead.

sqlcode: -20211

sqlstate: 428FJ

thanks
Reply With Quote
  #6 (permalink)  
Old 04-23-10, 09:37
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
Try listing the B tables columns out in your select statement.
Dave
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On