TSQL, Rename column of a returning table in user Function
Posted
by
user1433660
on Stack Overflow
See other posts from Stack Overflow
or by user1433660
Published on 2012-11-28T04:36:39Z
Indexed on
2012/11/28
5:04 UTC
Read the original article
Hit count: 148
I have defined function which returns table with 2 columns. Can I rename these columns so that resulting table would be like:
Press name | Sum of pages
?
CREATE FUNCTION F_3
(@press nvarchar(255))
RETURNS @table TABLE ( Press nvarchar(255),
PagesSum int )
AS
BEGIN
INSERT @table SELECT @press, SUM(Books.Pages)
FROM Books, Press
WHERE Press.Name = @press AND
Books.Id_Press = Press.Id
GROUP BY Press.Name
RETURN
END
GO
SELECT * FROM F_3('BHV')
GO
I've tried to do it like
Press AS 'Press name' nvarchar(255)
but that won't work.
© Stack Overflow or respective owner