T-SQL - function with default parameters

前端 未结 4 2037
傲寒
傲寒 2020-11-27 14:45

I have this script:

CREATE FUNCTION dbo.CheckIfSFExists(@param1 INT, @param2 BIT = 1 )
RETURNS BIT
AS
BEGIN
    IF EXISTS ( bla bla bla )
        RETURN 1;
          


        
4条回答
  •  臣服心动
    2020-11-27 14:50

    You can call it three ways - with parameters, with DEFAULT and via EXECUTE

    SET NOCOUNT ON;
    
    DECLARE
    @Table  SYSNAME = 'YourTable',
    @Schema SYSNAME = 'dbo',
    @Rows   INT;
    
    SELECT dbo.TableRowCount( @Table, @Schema )
    
    SELECT dbo.TableRowCount( @Table, DEFAULT )
    
    EXECUTE @Rows = dbo.TableRowCount @Table
    
    SELECT @Rows
    

提交回复
热议问题