简体   繁体   English

SQL如何在别名上内部联接

[英]SQL how to inner join on alias

Hi I am trying to do an inner join on an alias that has additional text onto the value, how would i do this? 嗨,我正在尝试在别名上进行内部联接,该别名在值上包含其他文本,我该怎么做?

This is what i have tried and it doesn't work: 这是我尝试过的,但不起作用:

INSERT INTO [dbo].[Inventory] ([VendorName], [PartNumber], [QuantityAvailable]) 
    SELECT 'TestVendor', 'V/P' + [Partnumber] as PartNumber, [QuantityAvailable]
    FROM [dbo].[Bulk_Temp]
    inner join v_PartMaster on Bulk_Temp.PartNumber = v_PartMaster.FullPartNumber

I assume you want to use PartNumber from the SELECT in the ON clause. 我假设您要在ON子句中使用SELECT中的PartNumber You need to repeat the expression . 您需要重复该表达式。 . . or use some similar trick: 或使用类似的技巧:

INSERT INTO dbo.Inventory (VendorName, PartNumber, QuantityAvailable) 
    SELECT 'TestVendor', 'V/P' + Partnumber as PartNumber, QuantityAvailable
    FROM dbo.Bulk_Temp JOIN
         v_PartMaster 
         ON 'V/P' + PartNumber = v_PartMaster.FullPartNumber;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM