本文介绍了有没有办法减少代码或是否可以在单个选择查询中编写它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 CREATE FUNCTION [dbo]。[getEquipmentName] ( @ EquipmentId varchar ( 500 )) RETURNS varchar ( 500 ) AS 开始 声明 @ EquipmentName varchar ( 500 ) 选择 @ EquipmentName = EquipmentName FROM PMS_TBL_EQUIPMENT_MASTER 其中 convert ( varchar ( 60 ),UniqueId)= @ EquipmentId 如果 @ EquipmentName null select @ EquipmentName = SubEquipmentName FROM PMS_TBL_SUB_EQUIPMENT_MASTER 其中 convert ( varchar ( 60 ),UniqueId)= @ EquipmentId 如果 @ EquipmentName null 选择 @EquipmentName = SubFunctionalBlockName FROM PMS_TBL_SUB_FUNCTIONAL_BLOCK_MASTER 其中 convert ( varchar ( 60 ) ,UniqueId)= @ EquipmentId 如果 @ EquipmentName null 选择 @ EquipmentName = ' ''' return @ EquipmentName end 可以任何人建议我将上面的代码缩减为单个select语句吗?解决方案 CREATE FUNCTION [dbo].[getEquipmentName] (@EquipmentId varchar(500))RETURNS varchar(500)ASbegindeclare @EquipmentName varchar(500)select @EquipmentName = EquipmentNameFROM PMS_TBL_EQUIPMENT_MASTER where convert(varchar(60),UniqueId)=@EquipmentIdif @EquipmentName is nullselect @EquipmentName = SubEquipmentNameFROM PMS_TBL_SUB_EQUIPMENT_MASTER where convert(varchar(60),UniqueId)=@EquipmentIdif @EquipmentName is null select @EquipmentName = SubFunctionalBlockNameFROM PMS_TBL_SUB_FUNCTIONAL_BLOCK_MASTER where convert(varchar(60),UniqueId)=@EquipmentIdif @EquipmentName is null select @EquipmentName=''''return @EquipmentNameendcan any one suggest me to reduce the above code into a single select statement? 解决方案 这篇关于有没有办法减少代码或是否可以在单个选择查询中编写它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 06:39