×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SELECT UNION syntax

SELECT UNION syntax

SELECT UNION syntax

(OP)
I am using the sql statement below with SQL Server and it works ok. The syntax is not valid against an Informix db, any ideas why?

Select Curr_ISO_Code,1 as type from Currency where Curr_Status = 'A' and Curr_ISO_Code = 'GBP' union Select Curr_ISO_Code,2 as type from Currency where Curr_Status = 'A' and Curr_ISO_Code = 'USD' union Select Curr_ISO_Code,3 as type from Currency where Curr_Status = 'A' and Curr_ISO_Code = 'HKD' union Select Curr_ISO_Code,4 as type from Currency where Curr_Status = 'A' and Curr_ISO_Code not in ('GBP','USD','HKD') order by type DESC

Thanks

RE: SELECT UNION syntax

Tom:

I have no experience using the "as type" syntax, although I believe Informix supports it.  Informix has no "currency" data type;  You might try "money".

Regards,

Ed
Schaefer

RE: SELECT UNION syntax

(OP)
I am not using the currency data type within the sql, it is the name of the table.

All I want to do is select the curr_iso_code from the currency table where the status is 'A' and ordr the curr_iso_codes by type 4, type 3, type 2, type 1

thanks

RE: SELECT UNION syntax

Tom:

Sorry, it's an understatement to say I "misunderstood".  Informix calls this "sorting by a literal value" so it should look something like this:

Select "1", Curr_ISO_Code, from Currency
   where Curr_Status = 'A' and Curr_ISO_Code = 'GBP'
union
Select "2", Curr_ISO_Code from Currency
where Curr_Status = 'A' and Curr_ISO_Code = 'USD'
union
Select "3", Curr_ISO_Code from Currency
where Curr_Status = 'A' and Curr_ISO_Code = 'HKD'
union
Select "4", Curr_ISO_Code from Currency where Curr_Status = 'A' and Curr_ISO_Code not in ('GBP','USD','HKD')
order by 1, 2, 3, 4 DESC

I don't have time to test this, but I've tried it before with just one union.  If you have a problem with the 'order by' and DESC, I might try reversing the select from "4" down to "1".

Regards,

Ed
Schaefer

RE: SELECT UNION syntax

Tom:

Let's try that again:

Select "1", Curr_ISO_Code, from Currency
   where Curr_Status = 'A' and Curr_ISO_Code = 'GBP'
union
Select "2", Curr_ISO_Code from Currency
where Curr_Status = 'A' and Curr_ISO_Code = 'USD'
union
Select "3", Curr_ISO_Code from Currency
where Curr_Status = 'A' and Curr_ISO_Code = 'HKD'
union
Select "4", Curr_ISO_Code from Currency where Curr_Status = 'A' and Curr_ISO_Code not in ('GBP','USD','HKD')
order by 1 DESC

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close