Question : How to convert First Function from MS Acess to T-SQL

Hi,
I have the following query from MS Access Database how do I convert this into Sql Server 2005, as it does not use the First Function.

SELECT
TableA!OrderNo AS [Order Ref],
TableA!FixException AS [Fix Exception],
IIf(TableB!CallNo Is Not Null,"Complete",IIf(TableA!ScheduledDate Is Null,"To be Planned",TableD!Status)) AS status,
TableA!OrderField AS [Order Activity Ref],
First(TableA!BADCallNo) AS [BAD Number],
TableA!ScheduledDate AS [Scheduled Date],
TableC!FirstOfSerialNumber AS [Serial Number],
TableA!SLADate AS [SLA Date]
FROM
      ((TableA LEFT JOIN TableD
ON TableA.OrderNo=TableD.OrderNo) LEFT JOIN TableC
ON TableD.OrderNo=TableC.OrderNo) LEFT JOIN TableB
ON TableA.BADCallNo=TableB.CallNo
GROUP BY
      TableA!OrderNo,
      TableA!FixException,
      IIf(TableB!CallNo Is Not Null,"Complete",IIf(TableA!ScheduledDate Is Null,"To be Planned",TableD!Status)),
      TableA!OrderField ,
      TableA!ScheduledDate,
      TableC!FirstOfSerialNumber,
      TableA!SLADate
HAVING
      (((TableA.ModelId) Like "BAD*")
And ((TableB.GlobalName) Is Null
Or (TableB.GlobalName)="TEST")
And ((TableD.AccountNumber)="ABC123")
And ((TableD!AssetToRemove)<>"9999"
And (TableD!AssetToRemove)<>"9998"
And (TableD!AssetToRemove)<>"9997")
And ((TableC!CategoryId)<>"N/A"))
ORDER BY
TableA!AcutalInstallationDate DESC;

Thanks

Answer : How to convert First Function from MS Acess to T-SQL

you refer to this:
>First(TableA!BADCallNo) AS [BAD Number],

so:
>Would it be possible for you to rewrite what the query should be
yes, if I knew the rules for the paritioning/ordering should be.

usually, the PARTITION BY is the same the GROUP BY of the query, and the ORDER BY for ROW_NUMBER() is the same as the ORDER BY of the main query.
however, it's basically what you request it to be.
Random Solutions  
 
programming4us programming4us