473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Merging two rows within same table

Hi,
I have a table like this.

IOMode Date EmployeeID EmpName
O 2007-02-28 16:46:00.000 FI0001258 M.MANIGANDAN
I 2007-02-28 07:47:00.000 FI0001258 M.MANIGANDAN
Now I want to merge these 2 rows into a single row.The employee is present only if IOMode has both I and O else his presence is invalid. How to check whether the employee is present for that particular date?
Please help.
May 3 '07 #1
2 3303
frozenmist
179 Expert 100+
Hi,
You can actually group by the IO,DATE and EMPNAME. IF it returns more than one row after group by then,it means that employee has I and O in his IO .
This would work i think
Expand|Select|Wrap|Line Numbers
  1.  
  2. select case  when count(a.cnt)>=2 then 'Present'  else 'not present' end as status from (SELECT COUNT(*) cnt FROM Table WHERE NAME=<somename> and DATE=<somedate>  GROUP BY IO,NAME,DATE ) a
  3.  
  4.  
Cheers
May 7 '07 #2
Thank you Mr.Frozenmist, I will try your code too. i tried with exist function and its working.
Here's the code

Create procedure [dbo].[USP_Unpunched_Select]
@EmpCode varchar(20),
@StartDate varchar(20),
@EndDate varchar(20)
AS
select Distinct EmpCode,EmpName,DeptName
from NewView
where EmpCode=@EmpCode
and not Exists
(select IOMODE from NewView where IOMODE = 'I' and
EmpCode=@EmpCode and (PDate between @StartDate and @EndDate)
and not Exists (select IOMODE from NewView where IOMODE = 'O'
and EmpCode=@EmpCode and (PDate between @StartDate and @EndDate)))
May 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jason | last post by:
I need to populate a table from several sources of raw data. For a given security (stock) it is possible to only receive PARTS of information from each of the different sources. It is also...
2
by: Klatuu | last post by:
Whew, I've struggled my way through figuring out how to use XML to transport data..now I can imagine what having a baby is like :) But, I'm stuck now. I generate the XML (single table, no...
0
by: Walt Borders | last post by:
Hi, My problem: Merging two datasets deletes parent elements, preserves all children. I've created two dataSets. Each use the same schema, parent-child nested tables. The first dataSet is...
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
1
by: mrclash | last post by:
Hello, I have a Database in a SQL Server 2000 where I have different users tables with equal fields like this: id (int) email (varchar) name (varchar) address (varchar) joinedon (datetime)
3
by: Ralph Smith | last post by:
I have two identical databases on two different servers and I need to add the data in tables from one server to the tables in the other server. Is there a way to do that in mysql? thanks, Ralph
6
by: dannylam4 | last post by:
Hello, I've got a question about merging/concatenating rows. There's a similar topic here: Combining Multiple Rows of one Field into One Result but I didn't know if I should hijack it. Basically, I...
2
by: Neil Chambers | last post by:
I am trying to get my head around dataset merging but despite a little research I could still use a pointer (or ten). Basically I want to perform an outer join operation on a dataset (created from...
1
by: akdemirc | last post by:
Hi, My question is about retrieving single records based on a time column, i mean the result set should not include duplicate rows for a unique time value as an example: A B C ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.