Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
deanglen
Yak Posting Veteran
65 Posts |
Posted - 2014-01-27 : 05:15:08
|
Running this query is fineselect distinct o.OrderDate, o.OrderNumber, c.CustomerID, c.FirstName, c.LastName, c.Email, c.Phone, o.OrderTotal, c.CustomerLevelIDfrom customer cjoin dbo.Orders_ShoppingCart os with (NOLOCK) on os.CustomerID = c.CustomerIDjoin dbo.Product p with (NOLOCK) on p.ProductID = os.ProductIDjoin dbo.Orders o with (NOLOCK) on o.OrderNumber = os.OrderNumberjoin dbo.PromotionUsage pu on pu.OrderID = o.OrderNumber join dbo.Promotions pm ON pm.ID = pu.PromotionID and c.CustomerLevelID = '5'and o.OrderDate >=dateadd(day,datediff(day,0,GetDate())- 7,0)order by o.OrderDate, c.CustomerIDBut when I try to add c.Notes into the select line I getMsg 421, Level 16, State 1, Line 1The ntext data type cannot be selected as DISTINCT because it is not comparable.Any idea how I can get this to run? |
|
gecew
Starting Member
10 Posts |
Posted - 2014-01-27 : 05:33:28
|
select distinct(c.CustomerID),c.Notes, o.OrderDate, o.OrderNumber, c.FirstName, c.LastName, c.Email, c.Phone, o.OrderTotal, c.CustomerLevelIDfrom customer cjoin dbo.Orders_ShoppingCart os with (NOLOCK) on os.CustomerID = c.CustomerIDjoin dbo.Product p with (NOLOCK) on p.ProductID = os.ProductIDjoin dbo.Orders o with (NOLOCK) on o.OrderNumber = os.OrderNumberjoin dbo.PromotionUsage pu on pu.OrderID = o.OrderNumber join dbo.Promotions pm ON pm.ID = pu.PromotionID and c.CustomerLevelID = '5'and o.OrderDate >=dateadd(day,datediff(day,0,GetDate())- 7,0)order by o.OrderDate, c.CustomerID |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-27 : 07:16:46
|
quote: Originally posted by deanglen Running this query is fineselect distinct o.OrderDate, o.OrderNumber, c.CustomerID, c.FirstName, c.LastName, c.Email, c.Phone, o.OrderTotal, c.CustomerLevelIDfrom customer cjoin dbo.Orders_ShoppingCart os with (NOLOCK) on os.CustomerID = c.CustomerIDjoin dbo.Product p with (NOLOCK) on p.ProductID = os.ProductIDjoin dbo.Orders o with (NOLOCK) on o.OrderNumber = os.OrderNumberjoin dbo.PromotionUsage pu on pu.OrderID = o.OrderNumber join dbo.Promotions pm ON pm.ID = pu.PromotionID and c.CustomerLevelID = '5'and o.OrderDate >=dateadd(day,datediff(day,0,GetDate())- 7,0)order by o.OrderDate, c.CustomerIDBut when I try to add c.Notes into the select line I getMsg 421, Level 16, State 1, Line 1The ntext data type cannot be selected as DISTINCT because it is not comparable.Any idea how I can get this to run?
castit to nvarchar(max) and tryie like belowselect distinct o.OrderDate, o.OrderNumber, c.CustomerID, c.FirstName, c.LastName, c.Email, c.Phone, o.OrderTotal, c.CustomerLevelID,CAST(c.Notes AS nvarchar(max))from customer cjoin dbo.Orders_ShoppingCart os with (NOLOCK) on os.CustomerID = c.CustomerIDjoin dbo.Product p with (NOLOCK) on p.ProductID = os.ProductIDjoin dbo.Orders o with (NOLOCK) on o.OrderNumber = os.OrderNumberjoin dbo.PromotionUsage pu on pu.OrderID = o.OrderNumber join dbo.Promotions pm ON pm.ID = pu.PromotionID and c.CustomerLevelID = '5'and o.OrderDate >=dateadd(day,datediff(day,0,GetDate())- 7,0)order by o.OrderDate, c.CustomerID Ideally you shouldnt use text,ntext and image as they're deprecated from sql 2005 onwardsYou should be using varchar(max),nvarchar(max) or varbinary(max) instead------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|
|
|