Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT UNION syntax

Status
Not open for further replies.

TomBarrand

Programmer
Aug 9, 2000
162
GB
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
 
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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top