解决 MSSQL 存储过程 不识别 uuid 中划线问题
原因:存储过程 调用uuid参数处 引号问题
-- =============================================
-- Author:Hwq
-- Create date:20220408
-- Description:查询车辆设备运单信息
-- =============================================
CREATE PROCEDURE [dbo].[p_Web_Query_Common_QueryVehicleEquipmentWaybillInfo]
@FAgentGUID uniqueidentifier, -- 部门id
@FKey nvarchar(max) ,-- 关键字
@FSelectType int,-- 查询类型 -1: 全部查询 0:按车辆查;1:按设备查;2:按运单查;3按客户id
@FPageSize int,
@FPageIndex int
AS
BEGIN
DECLARE @StartRows int, @EndRows int, @SqlString varchar(max) ;
SET
@StartRows =(@FPageIndex-1)* @FPageSize + 1;
SET
@EndRows = @FPageIndex * @FPageSize;
IF @FSelectType = 0
BEGIN
SET @SqlString = 'AND trd.FVehicleName LIKE ''%' + @FKey + '%'''
END
ELSE IF @FSelectType = 1
BEGIN
SET @SqlString = 'AND trd.FAssetID LIKE ''%'+ @FKey + '%'''
END
ELSE IF @FSelectType = 2
BEGIN
SET @SqlString = 'AND trd.FWaybill LIKE ''%' + @FKey + '%'''
END
ELSE IF @FSelectType = 3
BEGIN
SET @SqlString = 'AND taa.FCustomerID LIKE ''%' + @FKey + '%'''
END
ELSE
BEGIN
SET @SqlString = ' '
END
BEGIN
EXEC ('
SELECT Count(1) FTotalCount
FROM T_RouteDeparture trd
LEFT JOIN T_AdminAsset taa ON
trd .FAssetGUID = taa.FGUID
LEFT JOIN T_AdminVehicle tav ON
trd .FVehicleGUID = tav.FGUID
WHERE trd.FStatus = 0
AND tav.FAgentGUID in (select FAgentGUID from dbo.f_Common_Query_SuperAdminAgentGUIDListByGUID( '''+@FAgentGUID +'''))
'+ @SqlString+';
');
EXEC('
WITH cte AS( SELECT
tav.FAgentGUID AS FAgentGUID ,
trd.FVehicleGUID AS FVehicleGUID,
trd.FVehicleName AS FVehicleName ,
trd.FWaybill AS FWaybill ,
trd.FAssetGUID AS FAssetGUID ,
trd.FAssetID AS FAssetID,
taa.FCustomerID AS FCustomerID ,
ROW_NUMBER() OVER(ORDER BY tav.FAgentGUID desc) AS RowNo
FROM T_RouteDeparture trd
LEFT JOIN T_AdminAsset taa ON trd .FAssetGUID = taa.FGUID
LEFT JOIN T_AdminVehicle tav ON trd .FVehicleGUID = tav.FGUID
WHERE
trd.FStatus =0
AND tav.FAgentGUID in (select FAgentGUID from dbo.f_Common_Query_SuperAdminAgentGUIDListByGUID( '''+@FAgentGUID +'''))
' + @SqlString+'
)SELECT cte.* from cte where
cte.RowNo BETWEEN '+@StartRows+' AND '+@EndRows+';
')
END
END
问题解决: