first_value'不是可识别的内置函数名称

时间:2012-04-25 14:58:53

标签: sql-server

您好我的问题是我的问题。 请查看两个不同版本的查询及其错误消息。

SELECT first_value(col1) AS 'inv',col2 
FROM dbo.table  
--first_value' is not a recognized built-in function name.  

SELECT dbo.first_value(col1) AS 'inv',col2 
FROM dbo.table  
--Cannot find either column "dbo" or the user-defined function or aggregate "dbo.first", or the name is ambiguous.

SELECT first_value(col1) AS 'inv',col2 
FROM dbo.table 
GROUP BY col2  
--'first' is not a recognized built-in function name.

SELECT dbo.first_value(col1) AS 'inv',col2 
FROM dbo.table 
GROUP BY col2  
--Cannot find either column "dbo" or the user-defined function or aggregate "dbo.first", or the name is ambiguous.  

请任何帮助!

1 个答案:

答案 0 :(得分:-1)

如果您尝试从表中提取顶部/第一条记录,则需要指定将行定义为第一行/第一行的条件

SELECT top 1  col1 AS inv,col2  
FROM dbo.table 
ORDER BY col1 --or whatever criteria you need here
据我所知,

first_value似乎是一个MS SQL Server 2012函数,它还需要一个排序子句 - http://msdn.microsoft.com/en-us/library/hh213018.aspx