我正在努力使我的SQL更优雅和/或减少我需要运行的查询数量。我有一组两个查询:
有没有办法把它们写成一个单独的 查询?
简化查询1:
UPDATE [tblManipulateD]
SET [tblManipulateD].[abbreviation] = RIGHT([tblManipulateD].[description],3)
WHERE [tblManipulateD].[description] LIKE “*abbrev:*";
简化查询2
UPDATE [tblManipualteD]
LEFT JOIN [tblStorage] ON ([tblManipulateD].[abbreviation] = [tblStorage].[storage abbreviation]
SET [tblManipualteD].[product code] = [tblStorage].[storage product]
WHERE [tblManipulateD].[description] LIKE “*abbrev:*";
同样,我想知道是否有一种方法(在一个查询中)根据主表的计算将辅助表连接到主表。感谢您的帮助和/或见解!
答案 0 :(得分:1)
是的,您可以加入说明栏的最后3个字符:
UPDATE [tblManipulateD]
SET [tblManipulateD].[abbreviation] = RIGHT([tblManipulateD].[description],3),
[tblManipualteD].[product code] = [tblStorage].[storage product]
FROM [tblManipulateD]
LEFT JOIN [tblStorage] ON RIGHT([tblManipulateD].[description],3) = [tblStorage].[storage abbreviation]
WHERE [tblManipulateD].[description] LIKE “*abbrev:*";