GrayMP

Untitled

Aug 8th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1.  
  2. IF OBJECT_ID (N'dbo.fn_GetUserGuidByOutgoingParcelId', N'FN') IS NOT NULL
  3. DROP FUNCTION dbo.fn_GetUserGuidByOutgoingParcelId;
  4. GO
  5. CREATE FUNCTION dbo.fn_GetUserGuidByOutgoingParcelId(@outgoingParcelID INT)
  6. RETURNS UNIQUEIDENTIFIER
  7. WITH SCHEMABINDING
  8. AS
  9. BEGIN
  10.  
  11. DECLARE @var UNIQUEIDENTIFIER;
  12. select TOP 1
  13. @var = o.userGuidID
  14. FROM psl_orders o
  15. JOIN psl_incomingParcels ip ON ip.orderID = o.id
  16. WHERE ip.outgoingParcelID = @outgoingParcelID;
  17.  
  18. RETURN @var;
  19. END;
  20. GO
  21.  
  22.  
  23. IF OBJECTPROPERTY (OBJECT_ID(N'[dbo].[fn_GetUserGuidByOutgoingParcelId]'),'IsDeterministic') = 1
  24. PRINT 'Function is detrministic.'
  25. ELSE IF OBJECTPROPERTY (OBJECT_ID(N'[dbo].[fn_GetUserGuidByOutgoingParcelId]'),'IsDeterministic') = 0
  26. PRINT 'Function is NOT detrministic'
  27. GO
  28.  
  29. --ALTER TABLE dbo.psl_outgoingParcels
  30. -- DROP COLUMN userGuidID
  31. --GO
  32. --ALTER TABLE dbo.psl_outgoingParcels
  33. -- ADD userGuidID as dbo.fn_GetUserGuidByOutgoingParcelId(id)
  34. --GO
  35.  
  36. SELECT dbo.fn_GetUserGuidByOutgoingParcelId(1);
  37. SELECT dbo.fn_GetUserGuidByOutgoingParcelId(58);
Advertisement
Add Comment
Please, Sign In to add comment