Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Last day of the month
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

44 Posts

Posted - 03/09/2014 :  05:57:22  Show Profile  Reply with Quote

I would like to find all orders which finish in the last day of the month

select orderid,orderdate,custid,empid from Sales.Orders
where convert (date,orderdate,120) in (convert(date,(SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,Sales.Orders.orderdate)+1,0)) from Sales.Orders),120))

Unfortunately this query return error message:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Pls help

Starting Member

2 Posts

Posted - 03/09/2014 :  06:37:51  Show Profile  Reply with Quote
I think the error message is quite clear: The subquery is returning more than 1 row, which is then being passed as an expression towards convert().

Also, this looks needlessly complex. I guess this should work:
select orderid,orderdate,custid,empid from Sales.Orders
where datepart(day, dateadd(day, 1, orderdate)) = 1
Basically, add 1 day and check if this is the first day of any month.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000