Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 29th, 2006, 02:58 AM
Phr34ker Phr34ker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 4 Phr34ker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 25 sec
Reputation Power: 0
Subqueries in SELECT

I've read somewhere that subqueries in the SELECT-part of the SQL Statement should work in Firebird 1.5. But the following example doesn't (and that's really all the sub-querying I've tested):

SELECT templateId, parentTemplate, name, (templateImage IS NULL) As hasImage, (templateData IS NULL) As hasData FROM template

As you can see, all I want to know is if two blob-fields has any data or not.
He gives me the error:
Engine Code : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, char 66
IS

Any idea of how to solve this? Since the blob-data can be quite large, loading the data at this stage is not an option.

Last edited by Phr34ker : September 29th, 2006 at 03:06 AM. Reason: Didn't tell what version of Firebird I was using

Reply With Quote
  #2  
Old September 29th, 2006, 03:10 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,917 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 14 h 31 m 53 sec
Reputation Power: 279
I think you syntax is simply wrong, you should use a CASE statement to check if the blob field is null and then set a flag accordingly.

Reply With Quote
  #3  
Old September 29th, 2006, 03:40 AM
Phr34ker Phr34ker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 4 Phr34ker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 25 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
I think you syntax is simply wrong, you should use a CASE statement to check if the blob field is null and then set a flag accordingly.


Something like this?:
SELECT template.templateId, parentTemplate, name,
CASE templateImage
WHEN NULL THEN 0
ELSE 1
END,
CASE templateData
WHEN NULL THEN 0
ELSE 1
END
FROM template


Cause that doesn't work. Seems he really doesn't appreciate NULL, NOT or IS in the select-part of a query (also tried with IS NULL after WHEN):
Dynamic SQL Error
SQL error code = -104
Token unknown - line 3, char 10
NULL

I even tried inserting this statement:
(templateId IN (SELECT templateId FROM template WHERE templateImage IS NULL)) As hasImage

But of course to no avail. It didn't like IN...

Reply With Quote
  #4  
Old September 29th, 2006, 03:52 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,917 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 14 h 31 m 53 sec
Reputation Power: 279
See this thread

Reply With Quote
  #5  
Old September 29th, 2006, 04:12 AM
Phr34ker Phr34ker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 4 Phr34ker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 25 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
See this thread


I'm having trouble understanding how to use COALESCE in a way such that it returns 1 if the BLOB-field isn't null, and 0 if it is null. FIrst of all, the datatypes are incompatible, but even if it weren't, COALESCE returns the object when it is not null - which would become a much to large dataset to handle.

COALESCE (templateImage, 0) AS hasImage
// Incompatible datatypes
// Returns the data when not null


Or did you mean the function that was desribed in the thread? Don't see how that would help me.

I'm currently considering making a main query with the basic data, and then two more querys - each listing the templateId:s where the specific blob-field is null, and then looping through both lists to see if the current templateId matches any of the templateIds in the two other recordsets. But that's really ugly if you ask me...

Reply With Quote
  #6  
Old September 29th, 2006, 04:27 AM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,007 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 13 h 7 m 13 sec
Reputation Power: 67
Quote:
Originally Posted by Phr34ker
eems he really doesn't appreciate NULL, NOT or IS in the select-part of a query
The CASE "part" only accepts a column or no expression at all
The WHEN part accepts only values when a column is used in CASE or it can compare an expression, when nothing is specified in the CASE part.
This works:
Code:
SELECT templateId, parentTemplate
       CASE 
          WHEN templateImage IS NULL THEN 0 
          ELSE 1
       END
FROM template

Reply With Quote
  #7  
Old September 29th, 2006, 05:17 AM
Phr34ker Phr34ker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 4 Phr34ker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 25 sec
Reputation Power: 0
Talking

Worked perfectly. Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Subqueries in SELECT


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT