SQLTeam.com | Weblogs | Forums

How to separate values by stick when Feature values for C and X is different?

I work on SQL server 2012 I face issue : I can't get all different value Feature one one row result

separated by sticky if it multiple difference

if one different then no need stick.

where c have value and x have value but both not equal each other

so How can i do that Please ?

    create table #replace
(
PartIdc int,
PartIdx int,
)
insert into #replace(PartIdc,PartIdx)
values
(1211,1300),
(2000,2200),
(3000,3100),
(4150,4200)

create table #FeatureNameandValues
(
PartId int,
FeatueName nvarchar(20),
FeaatureValue int
)
insert into #FeatureNameandValues(PartId,FeatueName,FeaatureValue)
values
(1211,'Weight',5),
(2000,'Tall',20),
(3000,'Weight',70),
(4150,'Tall',190),
(1211,'Tall',80),
(1300,'Weight',10),
(3100,'Size',150),
(4200,'Tall',130),
(1300,'Tall',20)

Expected Result :slight_smile:

Tall (80-20) | Weight(5-10) | Tall(190-130)

for more Explain see image below :slight_smile:

attached file
http://www.mediafire.com/file/mxyr8wr9k98za7o/ExplainReport.xlsx/file

Hi

looks like you don't have any experience in SQL .. are you a beginner ?
why are you being made to do this

how do you get the results below ?? is this the SQL
from where FeatureValueC FeatureValueX ? we get

Doing what you want is really easy ...

select  
          FeatueName
    	, PartIdc
    	, PartIdx 
    from 
         #replace a 
    	    right join 
         #FeatureNameandValues b 
    	      on a.PartIdc = b.PartId

1 Like

hi ahmed

My comments ....
looks like you don't have any experience in SQL .. are you a beginner ?
why are you being made to do this

Please don't take this the wrong way
I did not mean anything BAD or negative by it ..

I was just curious after seeing your posts over many months

I should have WORDED my asking better
Please forgive me

But i am still curious about who you are what you are doing what is your situation
i mean as far as TSQL is concerned

You don't have to answer if you don't want to

1 Like

Not sure what this is used for, looks so wild and unusual

;with src
as
(
select src.FeatueName, 
               case when src.FeatueName = tgt.FeatueName 
			     then  src.FeatueName + '(' + cast(src.FeaatureValue as varchar(50)) + '-' + cast(tgt.FeaatureValue as varchar(50)) + ')'
					else 'no match'
					end as kirikara
			  from #FeatureNameandValues src
			  join #replace b on src.PartId = b.PartIdc
			  join #FeatureNameandValues tgt on tgt.PartId = b.PartIdx
			  where  src.FeatueName = tgt.FeatueName
)
select  distinct STUFF((SELECT ' | ' + kirikara 
    from src
	FOR XML PATH('')), 1, 2, '') IncludedColumns
  from src

1 Like

thank you for reply it solved