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 > Please help to find mistake in this simple query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-24-09, 02:19
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
Question Please help to find mistake in this simple query

Please help to find the mistake in this:

if(select count(*) from sysibm.systables where type='T' and name='VIVEK'=1)
begin
alter table dbo.vivek drop column hai
end


Showing error ; DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: (;if;JOIN

Thanks in Advance
Vivek
Reply With Quote
  #2 (permalink)  
Old 01-24-09, 02:38
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
If you are using a stored proc then you may have to try this


Quote:
if((select count(*) from sysibm.systables where type='T' and name='VIVEK')=1)
then
alter table dbo.vivek drop column hai
end if
__________________
IBM Certified Database Associate, DB2 9 for LUW

Last edited by nick.ncs; 01-24-09 at 02:46.
Reply With Quote
  #3 (permalink)  
Old 01-24-09, 02:47
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
i tried with case. I am not using a procedure here

but its showing some error: DB2 SQL error: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: (;case
when ;JOIN

Actually my query in oracle is like this:

declare countValue integer; begin select count(*) into countValue from user_tables where table_name=upper('[Param.1]'); if countValue=1 then alter table [Param.1] drop column [Param.2]; end if; end;

i NEED TO CONVERT THIS TO db2
Reply With Quote
  #4 (permalink)  
Old 01-24-09, 02:51
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
As specified in your other post... you'll have to write a SP for that.... unless IBM has come up with something new in v9.5 which i don't think is the case...
__________________
IBM Certified Database Associate, DB2 9 for LUW
Reply With Quote
  #5 (permalink)  
Old 01-24-09, 02:53
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
Ok Sir,
ThanKs for your help.
Reply With Quote
  #6 (permalink)  
Old 01-24-09, 02:55
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
I have one more query n creating view.

CREATE VIEW DBO.View_name AS

SELECTcol1,col2,col3 FROM DBO.Tablename

where

DBO.Tablename.paramname=’Prodt1’

AND

DBO.Tablename.stepname=’Step1’

AND

DBO.Tablename.productname=’proc1’

AND

DBO.Tablename.operation=’Oper1’

fetch first row only



This is showing: DB2 SQL error: SQLCODE: -20211, SQLSTATE: 428FJ, SQLERRMC: null, which means “428FJ: ORDER BY is not allowed in the outer full-select of a view or materialized query table” from db2 help site.
Reply With Quote
  #7 (permalink)  
Old 01-24-09, 03:08
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Try without "fetch first row only"
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #8 (permalink)  
Old 01-24-09, 03:13
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
I need to fetch first row in that . i want to know how to use with the fetch ststement
Reply With Quote
  #9 (permalink)  
Old 01-24-09, 04:44
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
as doc indicates : fetch first rw is not supported with views
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #10 (permalink)  
Old 01-25-09, 14:19
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Use the ROW_NUMBER OLAP function to find the first row according to the criteria that define row order. Because... as you wrote it, DB2 has no clue which row you want to get in case there are duplicates. Thus, the semantics of the query are not clear at all.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #11 (permalink)  
Old 01-26-09, 10:59
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
Quote:
Originally Posted by vivek.vivek
Please help to find the mistake in this:
if(select count(*) from sysibm.systables where type='T' and name='VIVEK'=1)
begin
alter table dbo.vivek drop column hai
end
I am not sure what you are trying to do, but looks like part

select count(*) from sysibm.systables where type='T' and name='VIVEK'

is missing schema name - there could be more than 1 table with the same name and different schemas. Your query might find tables with different than 'dbo' schema and assumes that tables 'dbo.vivek' exists which is not correct.
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS

Last edited by MarkhamDBA; 01-26-09 at 11:05.
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