Click here to Skip to main content
15,887,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have below table

Name Email MobileNo
1 0 1



OUTPUT TABLE

FiledName IsValid
Name 1
Email 0
MobileNo 1

What I have tried:

I have used pivot logic but do not get required output.
Posted
Updated 19-Jun-18 2:02am
v2
Comments
Mohibur Rashid 19-Jun-18 1:49am    
Show us the query.

You have to unpivot[^] data ;)

SQL
DECLARE @tmp TABLE(Name INT, Email INT, MobileNo INT)

INSERT INTO @tmp(Name, Email, MobileNo)
VALUES(1, 0, 1)


SELECT FieldName, IsValid
FROM @tmp AS Pvt
UNPIVOT(IsValid FOR FieldName IN (Name, Email, MobileNo)) AS UnPvt
 
Share this answer
 
create table T (Name int,Email int,MobileNo int)
insert into T values(1,0,1)

select * from T

select FieldName,u.Isvaild from T unpivot(Isvaild for FieldName in (Name ,Email ,MobileNo)) u
 
Share this answer
 
Comments
suneel kumar gupta 26-Jun-18 5:46am    
Thanks a lot!!!!
I need the same solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900