Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Table valued function caching wrong column names

$
0
0

I have two Table-valued functions where one uses the other in a manner as below.

CREATE FUNCTION f1
(
  @@iduser INT
)
RETURNS TABLE
AS
RETURN
(
  SELECT [idf2] AS idf1, 0 AS [status],* FROM [dbo].[f2](ISNULL((SELECT [date] FROM [user] WHERE [iduser] = @@iduser), GETDATE())
)
CREATE FUNCTION f2
(
  @@date DATETIME
)
RETURNS TABLE
AS
RETURN
(
  --SQL Pivoting data and adding default values
  --So just adding some pseudo code

  SELECT field1 FROM [table]
  WHERE [datefield] = @@date
  
  
)

Then I changed a name of a column in the result set from f2, the columns and types remained exactly the same. I just change the name. f1 now keeps returning the old field name, while f2 returns the new field name.

i.e.

SELECT * FROM [dbo].[f1](1)
returns
oldfieldname
---
2012-01-01
---------------------------------------------

SELECT * FROM [dbo].[f2]('2012-01-01')

returns
newfieldname
---
2012-01-01

I would expect f1 to return the same column names as f2 with having to re-create f1 or flushing the caches.

This would imply that you always need to flush the caches each time you re-create a function to make sure any dependent object updates their meta data.

Now f2 is always dropped and re-created when changes are made to the function.


Viewing all articles
Browse latest Browse all 12963

Trending Articles