Sql判断是否为数字类型
前景提要:现有一批房屋数据,房屋的计量单位字段定义为Square,字段类型是varchar(50)。为的是便于用户输入资料:房屋单位可能是平米,那输入的数据就是28.5等等之类的数字。亦可能是 1 间。
客户要求:有面积的房屋显示面积,没有面积、以间为单位的房屋显示为0.
解决方法如下:
create proc Asset_QueryFenlistForReport
(
@pi_Action varchar(100),
@pi_PropertyCode varchar(100),
@pi_pageIndex INT,
@pi_pageSize INT,
@po_recordCount BIGINT OUTPUT
)
as
DECLARE @pt_StartRowIndex INT
DECLARE @pt_EndRowIndex INT
SET @pt_StartRowIndex = (@pi_pageIndex - 1) * @pi_pageSize + 1
SET @pt_EndRowIndex = @pi_pageIndex * @pi_PageSize
IF @pi_Action = 'getlist'
BEGIN
SELECT * FROM
(
SELECT Asset_ShopInfo.RentStatus, Asset_ShopInfo.RefRental, Asset_ShopInfo.BuildingCode, Asset_ShopInfo.ShopCode, Asset_ShopInfo.Square,
Asset_Contract.RendStartDate, Asset_Contract.RendEndDate, Asset_ShopInfo.PropertyCode
,'SquareNew'=(
case
--使用函数ISNUMERIC(参数)
when ISNUMERIC ([Square])=0 then '0'
--当输入表达式得数为一个有效的整数、浮点数、money 或 decimal 类型,那么 ISNUMERIC 返回 1;否则返回 0。
when ISNUMERIC ([Square])>0 then [Square]
end
),
'RentStatuss' = (
CASE
WHEN RentStatus = 0 THEN '空置'
WHEN RentStatus = 1 THEN '预定'
ELSE
'已租'
End),
'YearRefRental'=(RefRental * 12),
ROW_NUMBER() OVER (ORDER BY Asset_Contract.RendStartDate DESC) AS RowIndex
FROM Asset_Contract INNER JOIN
Asset_ContractShopInfo ON Asset_Contract.ContractCode = Asset_ContractShopInfo.ContractCode RIGHT OUTER JOIN
Asset_ShopInfo ON Asset_ContractShopInfo.ShopCode = Asset_ShopInfo.ShopCode
where Asset_ShopInfo.propertycode = @pi_propertycode
)bb
WHERE RowIndex BETWEEN @pt_StartRowIndex AND @pt_EndRowIndex
--得到总数
SELECT @po_recordCount = COUNT(*)
FROM Asset_Contract INNER JOIN
Asset_ContractShopInfo ON Asset_Contract.ContractCode = Asset_ContractShopInfo.ContractCode RIGHT OUTER JOIN
Asset_ShopInfo ON Asset_ContractShopInfo.ShopCode = Asset_ShopInfo.ShopCode
where Asset_ShopInfo.propertycode = @pi_propertycode
END