I am trying to established a Function to have multiple parameters as see below @SITENAME, @MARKET and @DATE.
ALTER FUNCTION [dbo].[Platform_Parser]
(
@SITENAME NVARCHAR(2000) NULL
,@MARKET NVARCHAR(2000) NULL
,@DATE Date NULL
)
RETURNS NVARCHAR(2000)
AS
BEGIN
RETURN
CASE
WHEN @SITENAME LIKE '%GOOGLE%' AND @DATE < '2022-01-01' AND @MARKET IN ('FR','DE') THEN 'TWITTER'
WHEN @SITENAME LIKE '%GOOGLE%' AND @DATE < '2022-01-01' AND @MARKET = 'UK' THEN 'YOUTUBE'
ELSE 'Unclassified'
END
END
GO
This is the data in [dbo].[MyTable]
| SiteName | Market | Date |
|---|---|---|
| FR | 11/11/2021 | |
| YAHOO | FR | 09/05/2021 |
| DE | 03/07/2021 | |
| UK | 05/12/2021 | |
| UK | 05/05/2022 | |
| YAHOO | DE | 03/02/2022 |
| YAHOO | UK | 21/03/2022 |
However, when I try to implement the function in a different view as below I experience the error that I have too many arguments.
SELECT
[dbo].[Platform_Parser]([SiteName],[Market],[Date]) AS [Publisher]
,[Market] AS [Market]
,[Date] AS [Date]
FROM [dbo].[MyTable]
Result should be as below
| Publisher | Market | Date |
|---|---|---|
| FR | 11/11/2021 | |
| YAHOO | FR | 09/05/2021 |
| DE | 03/07/2021 | |
| YOUTUBE | UK | 05/12/2021 |
| UK | 05/05/2022 | |
| YAHOO | DE | 03/02/2022 |
| YAHOO | UK | 21/03/2022 |
TYPEinINSERTthe rows into it. What are you actually trying to achieve here; i suspect what you have are asking here is an XY Problem.FROM, so having a table type doesn't fit with the current design. You need to explain in detail, the problem you are trying to solve. Provide sample data (in a consumable format) and expected results.