473,659 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merging two rows within same table

94 New Member
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 3314
frozenmist
179 Recognized Expert New Member
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
sudhaMurugesan
94 New Member
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_S elect]
@EmpCode varchar(20),
@StartDate varchar(20),
@EndDate varchar(20)
AS
select Distinct EmpCode,EmpName ,DeptName
from NewView
where EmpCode=@EmpCod e
and not Exists
(select IOMODE from NewView where IOMODE = 'I' and
EmpCode=@EmpCod e and (PDate between @StartDate and @EndDate)
and not Exists (select IOMODE from NewView where IOMODE = 'O'
and EmpCode=@EmpCod e 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
8333
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 possible to have conflicting data. I am looking to make a composite picture of a given security using the following rules: 1) The goal is to replace all NULL and Blank values with data
2
1537
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 indexes) and populate a dataset using READXML. I then merge the contents of that DS (call it DS1) with a second DS (call it DS2) that I've created on the form that will be used to process the data transfer. I did that so my SQL would be generated (I...
0
2894
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 loaded with historical data read from an XML file. The second dataSet has current data filled from a dataGrid.
1
4946
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. Query..I want to keep the fields seperatred. I do not want to sent on field with all accumulated languages from one person to Word. Each language should appear in the document in a separate cell Cross tables are not delivering the result I...
1
1534
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
3872
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
2123
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 have a single table in Access that looks like: Name - - - Address - -Email - - - - -Comments John Doe - 11211 - - - j2@g.com - lad John Doe - 41541 - - - q3@g.com -asd John Doe - 12345 - - - w2@g.com -ask And what I basically want it to look...
2
1853
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 a file operation) and the resulting sql query based on the contents of said dataset. Effectively I would end up with two dataset tables in my application. If I were writing this to action from two tables it would be thus: SELECT ds.id, db.*
1
1773
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 D Time ------------------------------------------------------------- x x x x 1 y y y y 1 z z z z ...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.