Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IF OBJECT_ID (N'dbo.fn_GetUserGuidByOutgoingParcelId', N'FN') IS NOT NULL
- DROP FUNCTION dbo.fn_GetUserGuidByOutgoingParcelId;
- GO
- CREATE FUNCTION dbo.fn_GetUserGuidByOutgoingParcelId(@outgoingParcelID INT)
- RETURNS UNIQUEIDENTIFIER
- WITH SCHEMABINDING
- AS
- BEGIN
- DECLARE @var UNIQUEIDENTIFIER;
- select TOP 1
- @var = o.userGuidID
- FROM psl_orders o
- JOIN psl_incomingParcels ip ON ip.orderID = o.id
- WHERE ip.outgoingParcelID = @outgoingParcelID;
- RETURN @var;
- END;
- GO
- IF OBJECTPROPERTY (OBJECT_ID(N'[dbo].[fn_GetUserGuidByOutgoingParcelId]'),'IsDeterministic') = 1
- PRINT 'Function is detrministic.'
- ELSE IF OBJECTPROPERTY (OBJECT_ID(N'[dbo].[fn_GetUserGuidByOutgoingParcelId]'),'IsDeterministic') = 0
- PRINT 'Function is NOT detrministic'
- GO
- --ALTER TABLE dbo.psl_outgoingParcels
- -- DROP COLUMN userGuidID
- --GO
- --ALTER TABLE dbo.psl_outgoingParcels
- -- ADD userGuidID as dbo.fn_GetUserGuidByOutgoingParcelId(id)
- --GO
- SELECT dbo.fn_GetUserGuidByOutgoingParcelId(1);
- SELECT dbo.fn_GetUserGuidByOutgoingParcelId(58);
Advertisement
Add Comment
Please, Sign In to add comment