SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Data should be merged according to same criteria i
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ankita.vinculum
Starting Member

5 Posts

Posted - 06/05/2012 :  07:04:44  Show Profile  Reply with Quote
Hi,

Please help me out in resolving my query. I have a table which have 5 columns : WorkRole, Update Type, User, Update Time, Newvalue as mentioned below. I want to merge the data of NewValue column. Initially data display like this.

Work Role Update Type User UpdateTime NewValue


Admin TSL Created varsha 11-05-2012 14:10
Work Role Name=Admin TSL, Security Filter=GA Admin TSL, Description=

Admin TSL Created varsha 11-05-2012 14:10
Work Role Name=Admin TSL, Role=GA Admin Role

Test Test Created Sharepoint 20-03-2012 17:22 Work Role Name=Test Test, Role=Bo

Test Test Created Sharepoint 20-03-2012 17:22 Work Role Name=Test Test, Role=Contract Owner UAT

Test Test Created Sharepoint 20-03-2012 17:22 Work Role Name=Test Test, Role=Default Role

Test Test Created Sharepoint 20-03-2012 17:22 Work Role Name=Test Test, Security Filter=Test Test, Description=

I want to display data like this mention below:

Work Role Update Type User UpdateTime NewValue


Admin TSL Created varsha
11-05-2012 14:10 Work Role Name=Admin TSL, Security Filter=GA Admin TSL,
Description= , Role=GA Admin Role

Test Test Created
Sharepoint 20-03-2012 17:22 Work Role Name=Test Test, Security Filter=Test Test, Description= ,Role=Bo, Contract Owner UAT, Default Role

This means that I want to merge the data of those columns which have same data for these columns- work role, update type, user and update time and if any Work Role have more than one role for same Update Type, User and Update Time as mention in 2nd data then all the Role should come as comma separated.

I am using sql server 2008.

Thanks in advance,

ankita

DonAtWork
Flowing Fount of Yak Knowledge

2111 Posts

Posted - 06/05/2012 :  10:14:48  Show Profile  Reply with Quote
Your roles should be in their own table. you do NOT store data as comma separated values in a column!!!!









How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

3827 Posts

Posted - 06/05/2012 :  12:08:02  Show Profile  Reply with Quote
As Don said you should normalize your data structure. However, I can't tell what data goes with which column. Can you post DDL, DML and expected output.

Here are some links that might help:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47069 Posts

Posted - 06/05/2012 :  12:24:18  Show Profile  Reply with Quote
From what I see, I guess what you're after is something like this

http://jahaines.blogspot.com/2009/06/concatenating-column-values-part-1.html

But again posted data is not in proper format so if its not what you want, please post data in required format

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ankita.vinculum
Starting Member

5 Posts

Posted - 06/07/2012 :  01:45:10  Show Profile  Reply with Quote
Initially data is displaying like this

create table events (WorkRole varchar(100),UpdateType varchar(100) , Users varchar(100),UpdateTime datetime(20) , NewValue nvarchar(max))

insert into events
select 'Admin TSL', 'Created', 'varsha', '11-05-2012 14:10', 'Work Role Name=Admin TSL, Security Filter=GA Admin TSL, Description='
union
select 'Admin TSL', 'Created', 'varsha', '11-05-2012 14:10', 'Work Role Name=Admin TSL, Role=GA Admin Role'
union
select 'Test Test', 'Created', 'Sharepoint', '20-03-2012 17:22', 'Work Role Name=Test Test, Role=Bo'
union
select 'Test Test', 'Created', 'Sharepoint', '20-03-2012 17:22', 'Work Role Name=Test Test, Role=Contract Owner UAT'
union
select 'Test Test', 'Created', 'Sharepoint', '20-03-2012 17:22', 'Work Role Name=Test Test, Role=Default Role'
union
select 'Test Test', 'Created', 'Sharepoint', '20-03-2012 17:22', 'Work Role Name=Test Test, Security Filter=Test Test, Description='

Now i want to merge and then display the data if column WorkRole, UpdateType, Users, UpdateTime is same

select 'Admin TSL', 'Created', 'varsha', '11-05-2012 14:10', 'Work Role Name=Admin TSL, Security Filter=GA Admin TSL, Description= ,Role=GA Admin Role'
union
select 'Test Test', 'Created', 'Sharepoint', '20-03-2012 17:22', 'Work Role Name=Test Test, Security Filter=Test Test, Description= ,Role=Bo, Contract Owner UAT, Default Role'


ankita
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000