Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Combine 2 rows

Author  Topic 

mpayne
Starting Member

3 Posts

Posted - 2013-07-01 : 17:57:09
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-01 : 18:15:51
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 - 2013-07-01 : 21:30:02
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 - 2013-07-01 : 21:32:12
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-07-02 : 00:23:17
hi mpayne,

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



--
Chandu
Go to Top of Page
   

- Advertisement -