Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Sybase > CHAR_LENGTH question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-05-07, 14:23
Malachi4 Malachi4 is offline
Registered User
 
Join Date: Nov 2006
Posts: 15
CHAR_LENGTH question

This syntax does not work, it returns all email_id's even nulls

PHP Code:
WHERE CHAR_LENGTH(Ltrim(rtrim(EMAIL_ID))) IS NOT NULL 

Samething with this one, it returns all email_id's:
PHP Code:
WHERE (datalength(Ltrim(rtrim(EMAIL_ID)))=0
Can anyone identify the problem?

THANK YOU!!
Reply With Quote
  #2 (permalink)  
Old 12-05-07, 16:50
Malachi4 Malachi4 is offline
Registered User
 
Join Date: Nov 2006
Posts: 15
Looks like it does not work if I have MIN(EMAIL_SEQ_ID) As EMAIL_SEQ_ID in the select section.....
Reply With Quote
  #3 (permalink)  
Old 12-06-07, 02:54
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 830
You probaly have inconsistant grouping.
Post your select statement
Reply With Quote
  #4 (permalink)  
Old 12-06-07, 11:23
Malachi4 Malachi4 is offline
Registered User
 
Join Date: Nov 2006
Posts: 15
Here is my sql syntax:

Quote:
SELECT PR_ID, MIN(EMAIL_SEQ_ID) As EMAIL_SEQ_ID, EMAIL_ID
FROM EMAIL
WHERE CHAR_LENGTH(Ltrim(rtrim(EMAIL_ID))) IS NOT NULL AND pr_id >= #StartPrid# AND pr_id <= #EndPrid#
ORDER BY pr_id;
Thanks for your help!!
Reply With Quote
  #5 (permalink)  
Old 12-07-07, 03:03
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 830
That is indeed non standard sql as your grouping is inconsistent
This Sybase extension is to allow an easy join of an aggregate value to the rest of your data
In your select statement the where clause only apply to the MIN() function
An equivalent to your query using standard sql will be
Code:
select a.PR_ID, b.EMAIL_SEQ_ID, a.EMAIL_ID from EMAIL a ,(select MIN(EMAIL_SEQ_ID) As EMAIL_SEQ_ID from EMAIL WHERE CHAR_LENGTH(Ltrim(rtrim(EMAIL_ID))) IS NOT NULL and PR_ID between 1 and 2) b
I think you'll have to group by PR_ID and decide which EMAIL_ID you want min or max or do you want the one corosponding to the min(EMAIL_SEQ_ID)

Post some sample data and the expected output
AND your modified sql query if you still have a problem.
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

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