Scalar Function in Azure Synapse A

Siddiqui, Bashir 41 Reputation points

I am trying to create UDF Scalar Function in Azure Synapse Analytics, but I am getting the error given below. I am trying to create table variable or temp table inside the Scalar Function but getting an error.

Msg 105041, Level 16, State 1, Line 9
The SELECT statement is not allowed in user-defined functions.

SELECT @min = MIN(id) , @Max = MAX(id) FROM #Temp

WHILE (@min IS NOT NULL AND @min <= @Max )

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,316 questions
0 comments No comments
{count} votes

Accepted answer
  1. HimanshuSinha-msft 19,376 Reputation points Microsoft Employee

    Hello @Siddiqui, Bashir ,
    Thanks for the ask and using Microsoft Q&A platform .
    As I understand the ask here is how to use a SELECT statement in a scalar function in Synapse , please do let me know if thats not the case .

    Unfortunately at this time we cannot use a SELECT statement in the body of the function . Please read about this more here


    We can use a SELECT in table valued function which is called out here . Adding a example with the snashot for clarity below .


    We request to please go ahead and log a feature request on the feedback portal .

    Product group does monitor the request and they can plan for the implementation in future .Once you log the feature request you will also be notified on the status of the request .

    Please do let me know how it goes .


    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    0 comments No comments

0 additional answers

Sort by: Most helpful