Visual Studio 2017のSql Serverデータベースプロジェクトでユーザ定義関数を作成しようとしましたが、ビルド時に奇妙なエラーが発生しました。このエラーは、自動SQLコードビルダによって生成されました:ユーザ定義関数の戻り値型のSql Serverデータベースプロジェクトエラー
このメッセージを伴っていたRETURNS /* Error: Unsupported type. */
:
「SQL80001: 'AS' 付近に不適切な構文DOUBLE、ID、NATIONAL、QUOTED_ID、TABLE期待し、またはVARIABLE。
この問題が発生したことがあるのは誰ですか?私は多くのフォーラムやヘルプサイトを見てきましたが、この問題は多くの人に起こったようですが、ユーザー戻り型、特にDataTablesに関する修正は見つかりませんでした。
これがなぜ発生するのか、それを修正する方法を知っている人はいますか?ここで
エラーが発生した私のコードです:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
public static DataTable getDailyEmpHrs(String strGroupName)
{
DataSet dsEmp = new DataSet("myEmpHrs");
dsEmp.Tables["myEmpHrs"].Columns.Add("ccnumber", typeof(int));
dsEmp.Tables["myEmpHrs"].Columns.Add("ccname", typeof(string));
dsEmp.Tables["myEmpHrs"].Columns.Add("cccode", typeof(string));
DataTable dsTable = dsEmp.Tables["myEmpHrs"];
return dsTable;
}
};
とVisual Studioは、このコードを生成します。
----------------------------------------------------------------------------
-- This code was generated by a tool.
--
-- Changes to this file may cause incorrect behavior and will be lost if
-- the code is regenerated.
----------------------------------------------------------------------------
CREATE FUNCTION [dbo].[getDailyEmpHrs] (@strGroupName [nvarchar](MAX))
RETURNS /* Error: Unsupported type. */
AS EXTERNAL NAME [project].[UserDefinedFunctions].[getDailyEmpHrs];
Go
// Generated Assembly Stuff below here
スカラー関数ではなくテーブル値関数を使用して、IEnumrable型を返します。 https://stackoverflow.com/questions/2243637/returning-table-with-clrを参照してください。 –