您可以創建這樣的表值函數:
CREATE FUNCTION [dbo].[tfu_RPT_SEL_Benutzer]
(
@in_mandant varchar(3)
,@in_sprache varchar(2)
,@in_show_alle bit = 1
)
RETURNS TABLE
AS
RETURN
(
SELECT
BE_ID AS RPT_ID
,@in_mandant AS RPT_MDT_ID
,BE_Vorname AS RPT_Vorname
,BE_Name AS RPT_Nachname
,BE_User AS RPT_User
,
CASE
WHEN LEN(ISNULL(BE_Vorname + ' ', '') + ISNULL(BE_Name, '')) > 0
THEN ISNULL(BE_Vorname + ' ', '') + ISNULL(BE_Name, '')
ELSE BE_User
END AS RPT_Name
,0 AS RPT_Sort
FROM T_Benutzer
UNION
SELECT
0 AS RPT_ID
,@in_mandant AS RPT_MDT_ID
,'' AS RPT_Vorname
,'' AS RPT_Nachname
,
(
SELECT TOP(1)
CASE UPPER(@in_sprache)
WHEN 'FR' THEN T_RPT_Translations.RTR_Kurz_FR
WHEN 'IT' THEN T_RPT_Translations.RTR_Kurz_IT
WHEN 'EN' THEN T_RPT_Translations.RTR_Kurz_EN
ELSE T_RPT_Translations.RTR_Kurz_DE
END AS RTR_Kurz
FROM T_RPT_Translations
WHERE (RTR_Status = 1)
AND (RTR_MDT_ID = 0)
AND (RTR_ReportName = 'All')
--AND (RTR_IsFlag = 1)
AND (RTR_ItemCaption = 'NA')
--AND (RTR_Code = 1)
) AS RPT_User
,
(
SELECT TOP(1)
CASE UPPER(@in_sprache)
WHEN 'FR' THEN T_RPT_Translations.RTR_Lang_FR
WHEN 'IT' THEN T_RPT_Translations.RTR_Lang_IT
WHEN 'EN' THEN T_RPT_Translations.RTR_Lang_EN
ELSE T_RPT_Translations.RTR_Lang_DE
END AS RTR_Lang
FROM T_RPT_Translations
WHERE (RTR_Status = 1)
AND (RTR_MDT_ID = 0)
AND (RTR_ReportName = 'All')
--AND (RTR_IsFlag = 1)
AND (RTR_ItemCaption = 'NA')
--AND (RTR_Code = 1)
) AS RPT_Name
,999999999 AS RPT_Sort
WHERE @in_show_alle = 1
)
然後你可以使用CT Es表內的值函數。
DECLARE @i integer
SET @i=5
;WITH CTE AS (
SELECT
BE_ID
,BE_ID * @i as idmul
FROM T_Benutzer
)
SELECT * FROM CTE
WHERE idmul > 62000
和查詢從功能
DECLARE @in_mandant varchar(3)
,@in_sprache varchar(2)
,@in_show_alle bit = 1
SET @in_mandant = '0'
SET @in_sprache = 'DE'
SET @in_show_alle = 'true'
SELECT *
FROM tfu_RPT_SEL_Benutzer(@in_mandant, @in_sprache, @in_show_alle)
WHERE RPT_User = 'N/A'
熱膨脹係數甲骨文的風格;) –