连表查询,字段由int类型转换为varchar类型,
SupplierFile表中 ProductId 为 varchar 类型,Product表中 ProductId 为 int 类型,就需要用
CAST(Product.ProductId as varchar)这样就把表Product中的int类型的ProductId转换为
varchar类型了,sql语句如下:
Create view [dbo].[View_SupplierFile] as
select p.Id,p.FileName,p.ValidType,p.FileType,p.ValidityTime,p.FileGUID,p.SupplierId,f.Id as FileUploadId,p.ProductId,
g.ProductName,e.SupplierName
from
SupplierFile p LEFT OUTER JOIN
Supplier e on p.SupplierId=e.SupplierId
LEFT OUTER JOIN
FileUpload f on p.FileGUID=f.GUID
LEFT OUTER JOIN
Product g on p.SupplierId=g.SupplierId and CAST(g.ProductId as varchar)=p.ProductId where not p.ProductId is null
GO