USE [Database]

IF OBJECT_ID('[Functions].[product_type_id]') IS NOT NULL
  DROP FUNCTION [Functions].[product_type_id];
GO
CREATE FUNCTION [Functions].[product_type_id](
  @product_id AS INT
)
RETURNS INT
BEGIN
  DECLARE @product_type AS INT;
  SET @product_type = (
    SELECT [product_type_id]
    FROM [Tables].[products]
	WHERE [id] = @product_id);
  RETURN @product_type;
END
