如何在SQL Server中使用连接时使用distinct来避免重复记录 [英] How to use distinct to avoid duplicate records while using joins in SQL server

查看:161
本文介绍了如何在SQL Server中使用连接时使用distinct来避免重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了下面的存储过程,这个工作正常但是获取了具有相同日期的重复记录。

HI I have created the below stored procedure this is working fine but fetching duplicate records with same date.

SELECT  
    RB.Billing_Account_ID__c AS AccountNumber,
    AR.Phone__c AS PhoneNumber,
    T.CreatedDate AS CreatedDate,  
    U.Name AS UserName,
    T.[Description] AS [Description],  
FROM Account AS AR    
    LEFT JOIN BCAccount AS  RB ON AR.ID = RB.Residential_Account__c  
    LEFT JOIN MyTask  AS T ON AR.ID = T.WhatId   
    LEFT JOIN [User] AS  U ON T.OwnerId=U.Id  
WHERE  T.[Subject] = 'ABC Testing' 
    and BETWEEN @PastDateTime AND @CurrentDateTime





我的结果显示如下



My result is displaying like below

2016-04-24 23:44:08.000
2016-04-24 23:44:08.000
2016-04-24 23:44:08.000



以上记录相同并显示为重复



i wnat以避免重复。

你能帮忙吗。



我尝试了什么:



我试图通过使用以下内容来避免重复,但它在我的工作中不起作用select命令


the above records are same and displaying as duplicate

i wnat to avoid duplicate.
Could you please help on this.

What I have tried:

I have tried to avoid duplicate by using the below things but it is not working in my select command

CONVERT(VARCHAR(10), YourDateColumn, 101),



i得到ntext数据不支持sql server中的不同。


i am getting "ntext data is not supporting distinct in sql server".

推荐答案

解决了,问题不是datetime提交,另一个提交的类型是ntext我有最终转换成nvarchar
Solved, the problem is not datetime filed, another filed is type is ntext that i have converted into nvarchar with max
I got solution. Thank you.


这篇关于如何在SQL Server中使用连接时使用distinct来避免重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆