我想在我的函数中创建视图,每当我想创建我的视图时,我只需要参考函数并调用它。
我写了这段代码但是我收到了一个错误:
create FUNCTION [dbo].[testFunc]()
RETURNS bigint
AS
BEGIN
IF OBJECT_ID ('dbo.r_Sales01_Requests__Duplicates', 'V') IS NOT NULL
DROP VIEW dbo.r_Sales01_Requests__Duplicates ;
go
create view r_Sales01_Requests__Duplicates (
CompanyID
,Branch
,Year
,VoucherType,VoucherNumber
,Date_Persian
,Row) as
select
CompanyID
,Branch
,Year
,VoucherType
,VoucherNumber
,Date_Persian
,Row
from t_SalesRequests
group by CompanyID, Branch, Year, VoucherType, VoucherNumber, Date_Persian, Row
having count(*)>1
return
END
注意:在创建函数时,以下部分对我来说非常重要。
IF OBJECT_ID ('dbo.r_Sales01_Requests__Duplicates', 'V') IS NOT NULL
DROP VIEW dbo.r_Sales01_Requests__Duplicates ;