Skip to content
Advertisement

concatenate columns based on blank columns

I am having three columns,- and / should be used as separator result should come in new column(File Index-sub Index/Year),if sub index is blank then result should be (File Index/Year).

  SELECT 
[ File Index].[File Index]
, [ File Index].[Sub Index]
, [ File Index].[Financial Year]
, [ File Index].[File Index] & [Sub Index] & [Financial Year] AS [Composite Index]
  FROM [File Index];

Advertisement

Answer

You can use IIF function: IIF(Condition;ConcatenationIfTrue;ConcatenationIfFalse)

  SELECT 
[ File Index].[File Index]
, [ File Index].[Sub Index]
, [ File Index].[Financial Year]
, IIF(ISNULL([Sub Index];[ File Index].[File Index] & "/" & [Financial Year];[ File Index].[File Index] & [Sub Index] & [Financial Year]) AS [Composite Index]
  FROM [File Index];
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement