简体   繁体   中英

SQL Server stored procedure returns value in select statement

I have no experience with stored procedures whatsoever so I want to ask if something like this is possible.

Stored procedure returns

replace(rtrim(replace(
       replace(rtrim(replace(cast(@returningValue as varchar(40)), '0', ' ')), ' ', '0')
       , '.', ' ')), ' ', '.')

and this is called like this

SELECT storedProcedure(aDecimalValue)
FROM   Table

You could do this with a SCALAR VALUED function..

CREATE FUNCTION dbo.TEST_FUNCTION_NAME1 (@returningValue  VARCHAR(40)) 
        RETURNS VARCHAR(40) AS 
    BEGIN 
    return replace(rtrim(replace(
       replace(rtrim(replace(cast(@returningValue as varchar(40)), '0', ' ')), ' ', '0')
       , '.', ' ')), ' ', '.')

    END

Then you could do some thing like

SELECT dbo.TEST_FUNCTION_NAME1(string)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM