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 > IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token "SELECT" was found

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-06, 08:55
rajesh438 rajesh438 is offline
Registered User
 
Join Date: Sep 2006
Posts: 12
Lightbulb IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token "SELECT" was found

[IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token "SELECT" was found following "test AS". Expected tokens may include: "(". SQLSTATE=42601



im getting the above error when i tried to execute the query below

CREATE TABLE test
AS
SELECT
'Zigma' Company,
'ANY' IP,
'ANY' Hostname,
CAST(TIMESTAMP(SUBSTR(CHAR('1/22/2007'),6,4) || '-' || SUBSTR(CHAR('1/22/2007'),3,2) || '-' || SUBSTR(CHAR('1/22/2007'),1,1) || ' 00:00:00') AS DATE) Expire,
'10.1' Version,
'y' IsLicensed,
CURRENT TIMESTAMP LastUpdated
FROM SYSIBM.SYSDUMMY1
FETCH FIRST 1 ROWS ONLY

Last edited by rajesh438; 09-27-06 at 13:14.
Reply With Quote
  #2 (permalink)  
Old 09-27-06, 09:43
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Unless this is a new feature in V9, you cannot create a table with a select statement. You can use CREATE TABLE LIKE...

Please refer to the SQL Reference manual of the appropriate DB2 version you are using.
__________________
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
  #3 (permalink)  
Old 09-27-06, 12:15
rajesh438 rajesh438 is offline
Registered User
 
Join Date: Sep 2006
Posts: 12
thank you feldman
Reply With Quote
  #4 (permalink)  
Old 09-27-06, 12:27
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
But you can create either a materialised query table or a view with "CREATE ... AS SELECT ..."
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #5 (permalink)  
Old 09-28-06, 02:17
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
hi Rajesh
just got curious why u are using

"CAST(TIMESTAMP(SUBSTR(CHAR('1/22/2007'),6,4) || '-' || SUBSTR(CHAR('1/22/2007'),3,2) || '-' || SUBSTR(CHAR('1/22/2007'),1,1) || ' 00:00:00') AS DATE) Expire "

u are converting it from date to timestamp, then again to date??

following options may be much more handy

values timestamp_iso(date('1/22/2007'))

1
--------------------------
2007-01-22-00.00.00.000000

or
values date('1/22/2007')

1
----------
2007-01-22

Regards
Rahul Singh
Reply With Quote
  #6 (permalink)  
Old 09-28-06, 02:24
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
one more thing
"FROM SYSIBM.SYSDUMMY1
FETCH FIRST 1 ROWS ONLY"

sysdummy1 contains only one row . so no need to add fetch....

regards,
Rahul Singh
Reply With Quote
  #7 (permalink)  
Old 09-28-06, 02:35
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by rahul_s80
values date('1/22/2007')
There is no guarantee that the output will look like "2007-01-22"; this is an installation-related global DB2 setting.
Use "CHAR('1/22/2007', ISO)" to force an ISO date format (or indeed the timestamp_iso function).
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #8 (permalink)  
Old 09-28-06, 02:48
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
When inserting or updating data into a date column, the ISO format 'YYYY-MM-DD' will also be recognized and stored correctly in DB2.

As mentioned by others, the output format depends on the installation location settings of the client (either the client which is on the server, or a remote client).
__________________
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
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