November 26, 2017 at 8:58 pm
How do you pass a table like this?;WITH TestTbl AS
(
SELECT * FROM myTable
)
CREATE FUNCTION Ex( TestTbl TableType READONLY)
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @name VARCHAR(MAX)
SELECT TOP 1 @name = Field1 FROM TestTbl
RETURN @name
END
November 27, 2017 at 1:54 am
You'll need to create a user defined table type, then DECLARE and INSERT the values into the and then pass that to your Function.
A better question, however, would be why are you using a scalar function to achieve this? They are not the fastest thing. Also, not sure what you're planning to achieve with a TOP 1 with an ORDER BY clause. Unless you're planning for the return result to always be random.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
November 27, 2017 at 3:30 am
This is purely hypothetical to see if it's possible to pass a table to a function created by the statement ;WITH
Is it not possible?
November 27, 2017 at 3:38 am
MinhL7 - Monday, November 27, 2017 3:30 AMThis is purely hypothetical to see if it's possible to pass a table to a function created by the statement;WITH
Is it not possible?
WITH is a Common Table Expression. It does not CREATE a table, it's an Expression, much like CASE is. You can't pass an expression to a Function. Your Syntax, above, would be like doing:CASE @ID WHEN 1 THEN TRUE ELSE FALSE END AS Boolean
CREATE FUNCTION Example (Boolean case) ....
That syntax is just plain wrong. 🙂
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
November 27, 2017 at 4:35 am
Ok thank you
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply