CREATE
TABLE
abc(Id
INT
IDENTITY(1,1),
fn VARCHAR(2),
mn VARCHAR(2),
ln VARCHAR(2))
GO
INSERT
INTO
abc VALUES('D'
,
'B',
'F')
GO
Select
*
FROM
ABC
GO
--
Query
Declare
@id int=1;
;WITH
T
AS
(
SELECT
*
FROM
(
SELECT
fn,
mn,
ln,
id FROM
abc Where
id=@id)
T
UNPIVOT
(
Items FOR
N IN
(fn,
mn,
ln))P
)
SELECT
Items AS
FullName
FROM
T
--
It won't select Item if that is null.
Cheers!!
No comments:
Post a Comment