Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

unique ID

$
0
0

Hi,

how can we show only unique id from one table .

below are two tables

SELECT [ID]
      ,[EmpID]
      ,[EmpName]
      ,[StartDate]
      ,[EndDate]
      ,[day]
      ,[date]
      ,[Service]
      ,[Venue]
      ,[StartTime]
      ,[EndTime]
      ,[Breakfast]
      ,[Lunch]
      ,[Dinner]
      ,[DailyTotal]
      ,[Total]
      ,[OnsiteHrs]
      ,[StandardHrs]
      ,[TravelHrs]
      ,[OvertimeHrs]
  FROM [table1].[dbo].[EmpTimesheet]
SELECT [ID]
      ,[ServiceID]
      ,[DayoftheWeek]
      ,[Date]
      ,[Services]
      ,[Venue]
      ,[ProjectName]
      ,[StartTime]
      ,[EndTime]
      ,[Breakfast]
      ,[Lunch]
      ,[Dinner]
      ,[Total]
      ,[HoursTotal]
      ,[DetID]
      ,[TravelHrs]
      ,[OnsiteHrs]
  FROM [Table2].[dbo].[DetailsTable]

both tables are having refernces.

select distinct e.EmpID,e.StartDate,e.EndDate,d.ProjectName from

EmpTimeSheet e left join DetailsTable d on e.EmpID=d.ServiceID order by EmpID

 

when i execute above query below is the output
1	2014-01-05 00:00:00.000	2014-01-11 00:00:00.000	AT&T Plaza
1	2014-01-05 00:00:00.000	2014-01-11 00:00:00.000	Dallas LoveField
1	2014-01-05 00:00:00.000	2014-01-11 00:00:00.000	Flower MOund
1	2014-01-05 00:00:00.000	2014-01-11 00:00:00.000	WinSphere/Wylie
2	2014-01-12 00:00:00.000	2014-01-18 00:00:00.000	AT&T Plaza
2	2014-01-12 00:00:00.000	2014-01-18 00:00:00.000	Dallas LoveField
2	2014-01-12 00:00:00.000	2014-01-18 00:00:00.000	WinSphere/Wylie
3	2014-01-19 00:00:00.000	2014-01-25 00:00:00.000	AT&T Plaza
3	2014-01-19 00:00:00.000	2014-01-25 00:00:00.000	Dallas LoveField
3	2014-01-19 00:00:00.000	2014-01-25 00:00:00.000	Flower MOund

This query gives unique ids

select distinct EmpID,EmpName,StartDate,EndDate from EmpTimesheet

1 ram 2014-01-05 00:00:00.000 2014-01-11 00:00:00.000
2 ram 2014-01-12 00:00:00.000 2014-01-18 00:00:00.000
3 ram 2014-01-19 00:00:00.000 2014-01-25 00:00:00.000
4 tom 2014-01-05 00:00:00.000 2014-01-11 00:00:00.000
6 ram 2014-01-26 00:00:00.000 2014-02-01 00:00:00.000
11 naveen 2014-01-05 00:00:00.000 2014-01-11 00:00:00.000
12 hema 2014-01-05 00:00:00.000 2014-01-11 00:00:00.000
13 hema 2014-01-12 00:00:00.000 2014-01-18 00:00:00.000
14 hema 2014-01-19 00:00:00.000 2014-01-25 00:00:00.000
17 hema 2014-01-26 00:00:00.000 2014-02-01 00:00:00.000


I want output something like below when im joining two tables

1 2014-01-05 00:00:00.000 2014-01-11 00:00:00.000 AT&T Plaza,Dallas LoveField,Flower MOund,WinSphere/Wylie

2 2014-01-12 00:00:00.000 2014-01-18 00:00:00.000 AT&T Plaza,Dallas LoveField,WinSphere/Wylie

3 2014-01-19 00:00:00.000 2014-01-25 00:00:00.000 AT&T Plaza,Dallas LoveField, Flower MOund

one more thing  want to show only datepart  2014-01-19



Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>