-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathtSQLt.Private_GetDataTypeOrComputedColumnDefinition.sfn.sql
More file actions
23 lines (23 loc) · 1.42 KB
/
tSQLt.Private_GetDataTypeOrComputedColumnDefinition.sfn.sql
File metadata and controls
23 lines (23 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
IF OBJECT_ID('tSQLt.Private_GetDataTypeOrComputedColumnDefinition') IS NOT NULL DROP FUNCTION tSQLt.Private_GetDataTypeOrComputedColumnDefinition;
---Build+
GO
CREATE FUNCTION tSQLt.Private_GetDataTypeOrComputedColumnDefinition(@UserTypeId INT, @MaxLength INT, @Precision INT, @Scale INT, @CollationName NVARCHAR(MAX), @ObjectId INT, @ColumnId INT, @ReturnDetails BIT)
RETURNS TABLE
AS
RETURN SELECT
COALESCE(cc.IsComputedColumn, 0) AS IsComputedColumn,
COALESCE(cc.ComputedColumnDefinition, GFTN.TypeName) AS ColumnDefinition
FROM (SELECT @UserTypeId, @MaxLength, @Precision, @Scale, @CollationName, @ObjectId, @ColumnId, @ReturnDetails)
AS V(UserTypeId, MaxLength, Precision, Scale, CollationName, ObjectId, ColumnId, ReturnDetails)
CROSS APPLY tSQLt.Private_GetFullTypeName(V.UserTypeId, V.MaxLength, V.Precision, V.Scale, V.CollationName) AS GFTN
LEFT JOIN (SELECT 1 AS IsComputedColumn,
' AS '+ cci.definition + CASE WHEN cci.is_persisted = 1 THEN ' PERSISTED' ELSE '' END COLLATE database_default AS ComputedColumnDefinition,
cci.object_id,
cci.column_id
FROM sys.computed_columns cci
)cc
ON cc.object_id = V.ObjectId
AND cc.column_id = V.ColumnId
AND V.ReturnDetails = 1;
---Build-
GO