Just wanted to know whether this will work i..e. CASE & ISNULL logic
SELECT
CASE WHEN ISNULL(NodeAttribute1, '') = '' THEN CaptionDATA else NodeAttribute1 END AS NodeAttribute1
Just wanted to know whether this will work i..e. CASE & ISNULL logic
SELECT
CASE WHEN ISNULL(NodeAttribute1, '') = '' THEN CaptionDATA else NodeAttribute1 END AS NodeAttribute1
yes it will work ...no need for isnull(col,'') = ''
use case when col1 is null then col123
please click arrow to the left for Sample data
DROP TABLE [#xyz];
GO
CREATE TABLE [#xyz]
(
[id] varchar(1) NULL
, [name] VARCHAR(100)
);
GO
INSERT INTO [#xyz] SELECT '1', 'gary';
INSERT INTO [#xyz] SELECT NULL, 'hope';
INSERT INTO [#xyz] SELECT NULL, 'soap';
GO
SELECT 'data',* from #xyz
go
SELECT 'SQL Output',
CASE WHEN [#xyz].[id] IS NULL THEN [#xyz].[name]
ELSE [#xyz].[id]
END
FROM
[#xyz];
You don't actually need a CASE expression:
Declare @testTable Table (NodeAttribute1 varchar(20), CaptionData varchar(20));
Insert Into @testTable (NodeAttribute1, CaptionData)
Values ('Node1', 'Caption1')
, ('', 'Caption2')
, (Null, 'Caption3')
, ('Node4', 'Caption4');
Select *
, NodeAttribute1 = coalesce(nullif(tt.NodeAttribute1, ''), tt.CaptionData)
From @testTable tt;