<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: scalar function in databricks in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/scalar-function-in-databricks/m-p/99779#M8772</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/92637"&gt;@Shree23&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;In Databricks, you can create scalar or tabular functions using SQL or Python. Here is the&amp;nbsp;&lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-create-sql-function.html" target="_self"&gt;documentation&lt;/A&gt;&amp;nbsp;.&lt;BR /&gt;I converted your SQL Server function to Databricks standards.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE FUNCTION gettrans(
  PickupCompany STRING,
  SupplyCountry INT,
  TxnSource STRING,
  locId STRING,
  ExternalSiteId STRING
) RETURNS INT
RETURN (
  SELECT CASE
    WHEN TxnSource = 'CDX' THEN (
      -- Add business logic here
      0
    )
    ELSE 1
  END
);

SELECT gettrans('Purolator', 'CAN', 'CHI', '123', 'MAIN') as transactions;&lt;/LI-CODE&gt;
&lt;P&gt;As you can see, the syntax is pretty straightforward. The &lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-datatypes.html" target="_self"&gt;datatype&lt;/A&gt; can be INT, STRING, ARRAY, DECIMAL...&amp;nbsp;&lt;BR /&gt;The variables don't need to be prefixed by anything (@). The rest of the logic is pretty similar to what you will find in SQL Server.&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Nov 2024 15:15:08 GMT</pubDate>
    <dc:creator>MathieuDB</dc:creator>
    <dc:date>2024-11-22T15:15:08Z</dc:date>
    <item>
      <title>scalar function in databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/scalar-function-in-databricks/m-p/54615#M8768</link>
      <description>&lt;P&gt;Hi Expert,&lt;/P&gt;&lt;P&gt;here is sql server scalar function how to convert in databricks function&lt;/P&gt;&lt;P&gt;SQL&lt;BR /&gt;CREATE function [dbo].[gettrans](@PickupCompany nvarchar(2),&lt;BR /&gt;@SupplyCountry int, @TxnSource nvarchar(10),&lt;BR /&gt;@locId nvarchar(50), @ExternalSiteId nvarchar(50))&lt;BR /&gt;RETURNS INT&lt;BR /&gt;AS&lt;BR /&gt;&lt;BR /&gt;BEGIN&lt;BR /&gt;DECLARE @worldSiteid INT&lt;BR /&gt;SET @worldSiteid = 0&lt;BR /&gt;&lt;BR /&gt;If (@TxnSource = 'CDX')&lt;BR /&gt;BEGIN&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 20:10:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/scalar-function-in-databricks/m-p/54615#M8768</guid>
      <dc:creator>Shree23</dc:creator>
      <dc:date>2023-12-04T20:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: scalar function in databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/scalar-function-in-databricks/m-p/54636#M8769</link>
      <description>&lt;P&gt;Suggestion pls&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 07:17:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/scalar-function-in-databricks/m-p/54636#M8769</guid>
      <dc:creator>Shree23</dc:creator>
      <dc:date>2023-12-05T07:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: scalar function in databricks</title>
      <link>https://community.databricks.com/t5/get-started-discussions/scalar-function-in-databricks/m-p/99779#M8772</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/92637"&gt;@Shree23&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;In Databricks, you can create scalar or tabular functions using SQL or Python. Here is the&amp;nbsp;&lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-create-sql-function.html" target="_self"&gt;documentation&lt;/A&gt;&amp;nbsp;.&lt;BR /&gt;I converted your SQL Server function to Databricks standards.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;CREATE OR REPLACE FUNCTION gettrans(
  PickupCompany STRING,
  SupplyCountry INT,
  TxnSource STRING,
  locId STRING,
  ExternalSiteId STRING
) RETURNS INT
RETURN (
  SELECT CASE
    WHEN TxnSource = 'CDX' THEN (
      -- Add business logic here
      0
    )
    ELSE 1
  END
);

SELECT gettrans('Purolator', 'CAN', 'CHI', '123', 'MAIN') as transactions;&lt;/LI-CODE&gt;
&lt;P&gt;As you can see, the syntax is pretty straightforward. The &lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-datatypes.html" target="_self"&gt;datatype&lt;/A&gt; can be INT, STRING, ARRAY, DECIMAL...&amp;nbsp;&lt;BR /&gt;The variables don't need to be prefixed by anything (@). The rest of the logic is pretty similar to what you will find in SQL Server.&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 15:15:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/scalar-function-in-databricks/m-p/99779#M8772</guid>
      <dc:creator>MathieuDB</dc:creator>
      <dc:date>2024-11-22T15:15:08Z</dc:date>
    </item>
  </channel>
</rss>

