Я получаю сообщение об ошибке
Процедура не имеет параметров и аргументы были предоставлены.
при выполнении хранимой процедуры, показанной ниже.Если я что-то не так делаю, помогите пожалуйста.Я трачу больше времени на это сейчас, поэтому просто хочу ускорить.Спасибо.
Я хотел бы знать, сравниваю ли я правильный тип данных для строковой переменной типа данных «CMFNUMBER» как «0» в динамическом запросе ниже.Я знаю, что если он не динамический, то я буду сравнивать как CMFNumber <> '0'.Только одна кавычка, но для динамических запросов, это CMFNumber <> '' 0 '', двойная кавычка?
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_GET_Rates]
@productIds VARCHAR(MAX) = NULL,
@productStatusIds VARCHAR(MAX) = NULL,
@pqrIds VARCHAR(MAX) = NULL,
@origin VARCHAR(10) = NULL,
@destination VARCHAR(10) = NULL,
@contractId VARCHAR(12) = NULL,
@originMode CHAR(1) = NULL,
@destinationMode CHAR(1) = NULL,
@oceanEquipmentCode VARCHAR(10) = NULL,
@orderUserSort VARCHAR(100) = NULL,
@queryOrderBy VARCHAR(MAX) = '[CUSTOMER_NAME]',
@rowLimit INT = 0,
@startRow INT = 0,
@endRow INT = 0
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sSQL NVARCHAR(MAX),
@sWhere VARCHAR(MAX),
@condition VARCHAR(MAX),
@condition1 VARCHAR(MAX),
@CTE NVARCHAR(MAX),
@sSELECT NVARCHAR(MAX),
@drop NVARCHAR(256)
SET @sSQL = 'SELECT DISTINCT
PQRP.PQR_ID,
PQRP.PRODUCT_ID,
P.PRODUCT_NAME,
P.PRODUCT_DSP_NAME,
PS.STATUS_DESCRIPTION
INTO
##PQRS
FROM
SCS_EPQR.DBO.PQR_PRODUCTS PQRP
JOIN
SCS_EPQR.DBO.PRODUCT P ON P.PRODUCT_ID = PQRP.PRODUCT_ID
JOIN
SCS_EPQR.DBO.PRODUCT_STATUS PS ON PS.PRODUCT_STATUS = PQRP.PRODUCT_STATUS WHERE
1=1
AND PQRP.PRODUCT_ID IN (COALESCE((SELECT TXT_VALUE FROM DBO.FN_PARSETEXT2TABLE_TEXTONLY(@productIds, '','')), PQRP.PRODUCT_ID))
AND PQRP.PRODUCT_STATUS IN (COALESCE((SELECT TXT_VALUE FROM DBO.FN_PARSETEXT2TABLE_TEXTONLY(@productStatusIds, '','')), PQRP.PRODUCT_STATUS))
AND PQRP.PQR_ID IN (COALESCE((SELECT TXT_VALUE FROM DBO.FN_PARSETEXT2TABLE_TEXTONLY(@pqrIds, '','')), PQRP.PQR_ID)) '
IF (@orderUserSort = 'TOTALCUSTOMERPROFILES')
SET @Condition = ', ISNULL(CPL.TOTALCUSTOMERPROFILES, 0) AS TOTALCUSTOMERPROFILE'
IF (@orderUserSort = 'TOTALCUSTOMERPROFILES')
SET @Condition1 = 'LEFT JOIN (SELECT CMFNUMBER, COUNT(DISTINCT(CUSTOMERPROFILEID)) AS TOTALCUSTOMERPROFILES
FROM
SCS_CUST_PROFILE.DBO.CUSTOMERPROFILELOCATIONS
WHERE
CMFNUMBER <> ''0''
AND CMFNUMBER IS NOT NULL
GROUP BY CMFNUMBER, CUSTOMERPROFILEID
) CPL
ON CAST(CPL.CMFNUMBER AS VARCHAR(50)) = CAST(C.ACCOUNT_NUMBER AS VARCHAR(50))'
SET @CTE = ';WITH CTE_RATE_TLI AS(
SELECT DISTINCT TLIREFERENCENUMBER
FROM SCS_EPQR.DBO.OCEAN_SHIPPING_DETAIL_NETWORK_COST
WHERE 1=1
AND ORIGIN_CODE = COALESCE(@origin, ORIGIN_CODE)
AND DEST_CODE = COALESCE(@destination, DEST_CODE)
AND CONTRACT_ID = COALESCE(@contractId, CONTRACT_ID)
AND ORIGIN_MODE = COALESCE(@originMode, ORIGIN_MODE)
AND DEST_MODE = COALESCE(@destinationMode, DEST_MODE)
AND OCEAN_EQUIPMENT_CODE = COALESCE(@oceanEquipmentCode, OCEAN_EQUIPMENT_CODE)
),
CTE_COM AS (
SELECT RT.TLIREFERENCENUMBER, COM.COMMODITY_DESCRIPTION
FROM
CTE_RATE_TLI RT
JOIN FMC_TLI_RW TLI
ON TLI.TLIREFERENCENUMBER = RT.TLIREFERENCENUMBER
JOIN FMC_COMMODITY_RW COM
ON COM.COMMODITY_NUMBER = TLI.COMMODITY_NUMBER
GROUP BY
RT.TLIREFERENCENUMBER, COM.COMMODITY_DESCRIPTION
)
SELECT *
INTO ##TEMPDATA
FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY @queryOrderBy) AS ROWNUM,
C.CUSTOMER_NAME,
CP.CUSTOMERNAME C_CUSTOMER_NAME,
C.CUSTOMER_NUMBER,
C.ACCOUNT_NUMBER,
PQR.QUOTE_NUM,
NC.*,
COM.COMMODITY_DESCRIPTION TLI_COMMODITY_DESCRIPTION,
PQRS.PRODUCT_NAME,
PQRS.PRODUCT_DSP_NAME,
PQRS.STATUS_DESCRIPTION PRODUCT_STATUS_DESCRIPTION,
EQUIP.OCEAN_EQUIPMENT_NAME,
DP.ORIGIN_LOCATION_NAME,
DP.DEST_LOCATION_NAME,
DP.COMMODITY_NAME,
NC_EXP_DATE = COALESCE(NC.MOD_EXPIRE_ON, NC.EXPIRE_ON),
NC_DEST_COUNTRY_CODE_HBL = LEFT( DP.DEST_CODE,2),
ORIGIN_COUNTRY_NAME = OCOUNTRY.COUNTRY_NAME,
DEST_COUNTRY_NAME = DCOUNTRY.COUNTRY_NAME,
NC_DEST_POSTAL= DP.DEST_POSTAL,
NC_ORIGIN_POSTAL = DP.ORIGIN_POSTAL,
TERMS_OF_SALE = DP.TERMS_OF_SALE,
NC_ORIGIN_COUNTRY_CODE_HBL = LEFT( DP.ORIGIN_CODE,2)
' + @condition + '
FROM
SCS_EPQR.DBO.OCEAN_SHIPPING_DETAIL_NETWORK_COST NC
JOIN ##PQRS PQRS
ON PQRS.PQR_ID = NC.PQR_ID
JOIN SCS_EPQR.DBO.PQR
ON PQRS.PQR_ID = PQR.PQR_ID
LEFT JOIN SCS_EPQR.DBO.OCEAN_SHIPPING_DETAIL_PARAMS DP
ON DP.OSDP_ID = NC.OSDP_ID
LEFT JOIN SCS_EPQR.DBO.COMPANY C
ON C.PQR_ID = NC.PQR_ID
LEFT JOIN WEBPM.DBO.BUS_OCEAN_EQUIPMENT EQUIP
ON EQUIP.OCEAN_EQUIPMENT_CODE = NC.OCEAN_EQUIPMENT_CODE
LEFT JOIN WEBPM.DBO.BUS_COUNTRY OCOUNTRY
ON DP.ORIGIN_COUNTRY_CODE = OCOUNTRY.COUNTRY_CODE
LEFT JOIN WEBPM.DBO.BUS_COUNTRY DCOUNTRY
ON DP.DEST_COUNTRY_CODE = DCOUNTRY.COUNTRY_CODE
LEFT JOIN CUSTOMERPROFILES CP
ON PQR.CP_ID = CP.CUSTOMERPROFILEID
LEFT JOIN CTE_COM COM
ON COM.TLIREFERENCENUMBER = NC.TLIREFERENCENUMBER
' + @Condition1 + '
WHERE
1=1
AND NC.ORIGIN_CODE = COALESCE(@origin, NC.ORIGIN_CODE)
AND NC.DEST_CODE = COALESCE(@destination, NC.DEST_CODE)
AND NC.CONTRACT_ID = COALESCE(@contractId, NC.CONTRACT_ID)
AND NC.ORIGIN_MODE = COALESCE(@originMode, NC.ORIGIN_MODE)
AND NC.DEST_MODE = COALESCE(@destinationMode, NC.DEST_MODE)
AND NC.OCEAN_EQUIPMENT_CODE = COALESCE(@oceanEquipmentCode, NC.OCEAN_EQUIPMENT_CODE)
)X
WHERE ROWNUM BETWEEN
CASE WHEN (@rowLimit > 0) THEN @startRow ELSE ROWNUM END
AND CASE WHEN (@rowLimit > 0) THEN @endRow ELSE ROWNUM END'
IF (@orderUserSort <> 'TOTALCUSTOMERPROFILES')
SET @sSELECT = 'SELECT ##TEMPDATA.*, ISNULL(CPL.TOTALCUSTOMERPROFILES, 0) TOTALCUSTOMERPROFILES FROM ##TEMPDATA
LEFT JOIN (
SELECT CMFNUMBER, COUNT(DISTINCT(CUSTOMERPROFILEID)) AS TOTALCUSTOMERPROFILES
FROM
SCS_CUST_PROFILE.DBO.CUSTOMERPROFILELOCATIONS
WHERE
CMFNUMBER <> ''0''
AND CMFNUMBER IS NOT NULL
AND CMFNUMBER IN (SELECT ACCOUNT_NUMBER FROM ##TEMPDATA WHERE ACCOUNT_NUMBER IS NOT NULL AND ACCOUNT_NUMBER <> ''0'')
GROUP BY CMFNUMBER, CUSTOMERPROFILEID
) CPL
ON CAST(CPL.CMFNUMBER AS VARCHAR(50)) = CAST(##TEMPDATA.ACCOUNT_NUMBER AS VARCHAR(50))'
ELSE
BEGIN
SET @sSELECT = 'SELECT * FROM ##TEMPDATA'
END
SET @drop = 'DROP TABLE ##PQRS, ##TEMPDATA'
EXEC SP_EXECUTESQL @sSQL, @CTE, @sSELECT, @drop, N'@productIds VARCHAR(max), @productStatusIds VARCHAR(max), @pqrIds VARCHAR(max), @origin VARCHAR(10), @destination VARCHAR(10),
@contractId VARCHAR(12), @originMode CHAR(1), @destinationMode CHAR(1), @oceanEquipmentCode VARCHAR(10), @orderUserSort VARCHAR(100), @queryOrderBy VARCHAR(max),
@rowLimit INT, @startRow INT, @endRow INT', @productIds, @productStatusIds, @pqrIds, @origin, @destination, @contractId, @originMode, @destinationMode, @oceanEquipmentCode,
@orderUserSort, @queryOrderBy, @rowLimit, @startRow, @endRow ;
SET NOCOUNT OFF
END