Compatible UNION query for postgresql and MS SQL Server

Поиск
Список
Период
Сортировка
От Randy Zierman
Тема Compatible UNION query for postgresql and MS SQL Server
Дата
Msg-id 4952D11C5863E6458C982AAE31774F722DAA@hsg-corp-apex.HelmSolutionsGroup.com
обсуждение исходный текст
Ответы Re: Compatible UNION query for postgresql and MS SQL Server  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general

I am adapting a java application to work with both SQL Server and postgresql 7.2.2.  I am having trouble with the following statement.

 

    String strSQL = "Select m.* from Message m, ASKUser u " +

        "where (m.JurisdictionID =  " + currentJurisdictionID + " AND DistributionType = 'J')  " +

        "OR DistributionType = 'M' OR DistributionType = 'S' " +

        "AND (Status = 'O'  " +

        "and u.ASKUserID = " + currentASKUserID + ") " +

        "Union " +

        "Select m.* from UserSchool us " +

        "inner join ASKUser u on u.ASKUserID = us.ASKUserID " +

        "inner join MessageSchool ms on ms.SchoolID = us.SchoolID " +

        "inner join Message m on m.MessageID = ms.MessageID " +

        "where us.ASKUserID = " + currentASKUserID +

        "ORDER BY m.Priority, m.DistributionType, m.CreationDate ";

 

The problem is in the ORDER BY clause.  If  the table alias (m.) is not given, SQL server complains that there is an ambiguous column reference.  With postgres, using the table alias produces the error “Relation “m” does not exist”

 

Is there any way, besides using column numbers, to use the same syntax for both databases?

 

В списке pgsql-general по дате отправления:

Предыдущее
От: Sean Chittenden
Дата:
Сообщение: TIMESTAMP WITH( OUT)? TIME ZONE indexing/type choice...
Следующее
От: Patrick Nelson
Дата:
Сообщение: RE in where