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
 Combine 2 rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mpayne
Starting Member

3 Posts

Posted - 07/01/2013 :  17:57:09  Show Profile  Reply with Quote
I am trying to combine rows if certain conditions are met...
When Parent guid in row 3 = guid in row 2 put the name on row 3

Category DisplayName ParentGUID GUID IsLeafNode
NULL Payne, Michele 0 1588204020 1
New category Payne, Michele 0 1588304020 0
NULL Payne, Michele 1588304020 1588404020 1

There can be multiple parent guids to one guid. This is what I have so far

select distinct Name category
,u.DisplayName
,cat.ParentGUID
,cat.GUID
,cat.IsLeafNode

from CV3HealthIssueBrowseItem cat
inner join CV3User u
on u.GUID = cat.UserGUID

where u.IDCode = 'mpayne'

so for example a user can have one category of cardiology and 10 health issues under that category - I want to display each health issue with its category. If the category is empty - just leave the category field empty...

Thank you in advance... this is driving me crazy. I did try subselects, but was getting the error I had one row for many results

James K
Flowing Fount of Yak Knowledge

3712 Posts

Posted - 07/01/2013 :  18:15:51  Show Profile  Reply with Quote
quote:
Originally posted by mpayne

I am trying to combine rows if certain conditions are met...
When Parent guid in row 3 = guid in row 2 put the name on row 3

Category      DisplayName	ParentGUID	GUID	    IsLeafNode
NULL	      Payne, Michele	0	        1588204020	1
New category  Payne, Michele	0	        1588304020	0
NULL	      Payne, Michele	1588304020	1588404020	1


There can be multiple parent guids to one guid. This is what I have so far

select distinct Name category
,u.DisplayName
,cat.ParentGUID
,cat.GUID
,cat.IsLeafNode

from CV3HealthIssueBrowseItem cat
inner join CV3User u
on u.GUID = cat.UserGUID

where u.IDCode = 'mpayne'

so for example a user can have one category of cardiology and 10 health issues under that category - I want to display each health issue with its category. If the category is empty - just leave the category field empty...

Thank you in advance... this is driving me crazy. I did try subselects, but was getting the error I had one row for many results



Are you trying to copy the DisplayName FROM row 3 in this example to TO rows 1 and 2, or the other way around?

From your description it seemed to me like it is the other way around, i.e., you are trying to copy the DisplayNames from Rows 1 and 2 to Row 3. If that is so, what do you want to do, copy both names as a comma-separated? If they are both the same, as in this case, do you want it to be repeated?

Post some sample input data and the corresponding output you are looking for. That would make it easier for someone to understand what you are trying to do.
Go to Top of Page

mpayne
Starting Member

3 Posts

Posted - 07/01/2013 :  21:30:02  Show Profile  Reply with Quote
Hi James,

Row 1 would be left as is
Row 2 and Row 3 would be combined (parent guid row 3 = guid row 2)
I want row 2's category to be displayed on row 3

Does that make sense?
Go to Top of Page

mpayne
Starting Member

3 Posts

Posted - 07/01/2013 :  21:32:12  Show Profile  Reply with Quote
So I want the result to be
Category DisplayName ParentGUID GUID IsLeafNode
NULL Payne, Michele 0 1588204020 1
New Category Payne, Michele 1588304020 1588404020 1
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 07/02/2013 :  00:23:17  Show Profile  Reply with Quote
hi mpayne,

Provide us sample data for CV3HealthIssueBrowseItem, CV3User tables and also expected result for that data...



--
Chandu
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.08 seconds. Powered By: Snitz Forums 2000