Avatar of chokka
chokka
Flag 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

Microsoft SQL Server 2005Microsoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Lowfatspread

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Lowfatspread

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61