Back to OIM Explorer

dbo.QBM_FSQIndexColumns

Scalar FunctionSQL_SCALAR_FUNCTIONSandbox DB

Scalar Function.

Source: sandbox-db sys.sql_modules

Source size: 1.101 characters

Interpretation

  • Database function. Usually supports views, validation, or calculated predicates; look at referenced-by entries for callers.

Relations

  • No extracted relations.

Typed Edges

  • No typed edges extracted for this source.

References

  • No direct source references extracted.

Referenced By

Complete Source

SQL45 lines
1CREATE FUNCTION dbo.QBM_FSQIndexColumns(2  @TableOrTypeName varchar(30),3  @IndexName varchar(30),4  @IncludedColumns BIT5) RETURNS nvarchar(max6)7AS8BEGIN9  RETURN(10  SELECT11    isnull(String_agg(convert(nvarchar(max), CONCAT(x.name, CASE x.is_descending_key12    WHEN 1 THEN13    ' desc'14  ELSE ''15  END)), ',') WITHIN16  GROUP(17  ORDER BY x.key_Ordinal, x.index_column_id), N '')18  FROM(19  SELECT20    c.name, ik.key_Ordinal, ik.index_column_id, ik.is_descending_key21  FROM(22  SELECT t1.object_id23  FROM sys.objects t124    WITH(readpast)25  WHERE26    t1.name = @TableOrTypeName27  UNION all28  SELECT t2.type_table_object_id29  FROM sys.table_types t230    WITH(readpast)31  WHERE32    t2.name = @TableOrTypeName) AS t33  JOIN sys.indexes i34    WITH(readpast)35    ON t.Object_id = i.Object_id AND i.name = @Indexname AND i.is_hypothetical = 0 AND i.type NOT IN(3, 4,36  5, 6)37  JOIN sys.index_columns ik38    WITH(readpast)39    ON i.Object_id = ik.Object_id AND i.index_id = ik.index_id AND ik.is_included_column = @IncludedColumns40  JOIN sys.columns c41    WITH(readpast)42    ON c.Object_id = t.Object_id AND c.Column_id = ik.Column_id43  WHERE44    i.is_primary_key = 0) AS x)45END
Open raw exported source
SQL ยท Raw9 lines
1  create   function dbo.QBM_FSQIndexColumns (@TableOrTypeName varchar(30) , @IndexName varchar(30) , @IncludedColumns bit ) returns nvarchar(max2)  as begin return( select isnull(String_agg( convert(nvarchar(max), concat(x.name , case x.is_descending_key when 1 then ' desc' else '' end ) )  , ','3 )  WITHIN GROUP ( ORDER BY x.key_Ordinal, x.index_column_id) , N'') from ( select c.name, ik.key_Ordinal, ik.index_column_id, ik.is_descending_key from4 (select t1.object_id from sys.objects t1 with (readpast) where t1.name = @TableOrTypeName union all select t2.type_table_object_id from sys.table_types5 t2 with (readpast) where t2.name = @TableOrTypeName ) as t join sys.indexes i with (readpast) on t.Object_id = i.Object_id and i.name = @Indexname  and6 i.is_hypothetical = 0  and i.type not in (3,4,5,6) join sys.index_columns ik with (readpast) on i.Object_id = ik.Object_id and i.index_id = ik.index_id7 and ik.is_included_column = @IncludedColumns join sys.columns c with (readpast) on c.Object_id = t.Object_id and c.Column_id = ik.Column_id where i.is_primary_key8 = 0 ) as x ) end 9