我有一个查询正在比较表中的uniqueidentifier和它的奇怪的一个。
SELECT * FROM vw_ryzex_CustomerAssets where BillToId='51ee47d2-eb97-4b12-8865-dab9a7f15a46'
因此,当我运行此查询时,我收到以下错误 将nvarchar值'00000000-0000-0000-0000-000000000000'转换为数据类型int。
时转换失败但是当我只选择前1000名时我得到的结果并没有发生错误我尝试了Casting并转换检查nulls我可以尝试跟随查询但是没有工作
SELECT * FROM vw_ryzex_CustomerAssets_V2 where CAST(BillToId as nvarchar(200))=Cast('51ee47d2-eb97-4b12-8865-dab9a7f15a46' as nvarchar(200))
SELECT * FROM vw_ryzex_CustomerAssets where (Case BillToId
when '00000000-0000-0000-0000-000000000000' Then NEWID()
ELSE BillToId
END) = '51ee47d2-eb97-4b12-8865-dab9a7f15a46'
有人可以帮我这个吗??
这是视图定义
ALTER VIEW [dbo].[vw_ryzex_CustomerAssets_V2] AS SELECT a.Id,
'~/Reports/BillToAssetDetails.aspx?btid='
+ CONVERT(VARCHAR(256), a.BillToId)
+ '&vidx=1&caid='
+ CONVERT(VARCHAR(256), a.Id) AS URL,
'~/Reports/BillToAssets.aspx?btid='
+ CONVERT(VARCHAR(256), a.BillToId)
+ '&vidx=1&caid='
+ CONVERT(VARCHAR(256), a.Id) AS EditUrl,
LEFT(a.PartDescription, 50) AS PartDescription,-- EKL:03042009
a.Quantity,
a.SerialNumber,
/* CASE ISNULL(s.Name,'') WHEN '' THEN a.Location ELSE s.Name + '(' + s.ErpId + ')
'+ a.Location END AS Location, */
a.Location,
s.NAME + '(' + s.ErpId + ')' AS SiteName,
--a.OrderId,
o.OrderGroupId AS OrderId,
a.OrderErpId,
a.OrderExt,
a.OrderLine,
a.DateCreated,
a.DateModified,
Isnull(ru.DisplayName, '') AS ModifiedBy,
a.BillToId,
a.PartNo,
b.NAME AS BillToName,
b.Description AS BillToDescription,
b.ErpId AS BillToErpId,
b.DateCreated AS BillToDateCreated,
b.DateModified AS BillToDateModified,
b.ModifiedBy AS BillToModifiedBy,
a.ProductId,
--p.ProductPartNo,
--p.ProductModel,
--p.ProductDescription as ProductDescription,
--p.ProductDateCreated,
--p.ProductDateModified,
--p.ProductModifiedBy,
Isnull(ol.UnitPrice, '0') AS UnitPrice,
ol.SalesTax,
Isnull(ol.TotalPrice, '0') AS TotalPrice,
ol.OrderErpId AS OrderLineId,
Isnull(ol.QuantityOrdered, '0') AS QuantityOrdered,
Isnull(ol.QuantityShipped, '0') AS QuantityShipped,
-- o.Created AS OrderDate,
Dateadd(mi, Datediff(mi, Getutcdate(), Getdate()), o.Created) AS OrderDate,
-- o.ShippedDate AS ShipDate,
Dateadd(mi, Datediff(mi, Getutcdate(), Getdate()), o.ShippedDate) AS ShipDate,
o.SalesPersonName AS SalesPersonDisplayName,
o.BillingCurrency AS Currency,
dbo.vw_PurchaseOrderPayments.PurchaseOrderPaymentNumber AS CustPo,
a.AssetNumber,
a.CustomerReference,
a.ModelNumber,
a.CustomField1Value AS xCust1,
a.CustomField2Value AS xCust2,
s.Id AS ShipToId,
s.AddressLine1 AS Address1,
s.AddressLine2 AS Address2,
s.AddressLine3 AS Address3,
s.City,
s.Country,
s.[State],
s.ZipCode AS Zip
FROM dbo.vw_PurchaseOrderPayments
RIGHT OUTER JOIN dbo.vw_PurchaseOrders AS o
ON dbo.vw_PurchaseOrderPayments.OrderFormId = o.OrderFormId -- EKL:03042009 chg from OrderGroupId to OrderFormId
RIGHT OUTER JOIN dbo.ryzex_CustomerAsset AS a
INNER JOIN dbo.ryzex_BillTo AS b WITH (NOLOCK)
ON a.BillToId = b.Id
AND Isnull(a.Inactive, 0) = 0
LEFT OUTER JOIN dbo.ryzex_ShipTo AS s WITH (NOLOCK)
ON a.ShipToId = s.Id
AND b.Id = s.BillToId
LEFT OUTER JOIN dbo.ryzex_Product AS p WITH (NOLOCK)
ON a.PartNo = p.ProductPartNo
LEFT OUTER JOIN dbo.vw_OrderLines AS ol
ON a.OrderErpId = ol.OrderErpId
AND a.OrderLine = ol.LineNumber
ON o.OrderErpNumber = a.OrderErpId
AND o.OrderExtensionNumber = a.OrderExt
LEFT OUTER JOIN dbo.ryzex_Users AS ru WITH (NOLOCK)
ON a.ModifiedBy = ru.Id
来自ryzex_CustomerAsset tbl的BillToId是一个非null uniqueidentifier