Link to home
Create AccountLog in
Avatar of chokka
chokkaFlag for United States of America

asked on

SQL - Order by Asc query

SQL 2005 / 2008

This query over here ...

select DateFilled from
                  (
                  select patcustid,DaysSupply,DateFilled from vOeOrderHistoryWide
                  union all
                  select patcustid,DaysSupply,DateFilled from vOeOrderWide
                  )as x
                  where patcustid = 8

Returns Null and Date Field.

When i filter the query with Order By Asc - It returns NULL. Instead of picking the NULL Value, i am looking for first lowest Date Filled.

How to tune the query to fetch the lowest Date Filled !!
select top 1 DateFilled from
			(
			select patcustid,DaysSupply,DateFilled from vOeOrderHistoryWide
			union all
			select patcustid,DaysSupply,DateFilled from vOeOrderWide
			)as x
			where patcustid = 8
			order by DateFilled asc

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account