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
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
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
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
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
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