Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Function A, scalar, returns smallint (a year)
Function B, scalar, returns smallint (a month)
Function C, table, displays users based on year and month.

They work fine.

I would like to set default parameter of Function C to come from Func A & B like:

@year smallint = SELECT FunctA(), @month smallint = SELECT FunctB()

Is there anyway around this?

We are on Azure SQL Managed Instance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
252 views
Welcome To Ask or Share your Answers For Others

1 Answer

On thing you could use is something like

IF @year IS NULL
BEGIN
  SET @year = functa();
END;

IF @month IS NULL
BEGIN
  SET @month = functb();
END;

(or whatever the analog syntax is in the DBMS you didn't disclose).
And when you want the defaults, pass NULLs as parameters.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...