将varchar转换为float ms sql时出错

时间:2013-06-14 14:13:15

标签: sql sqldatatypes

我在此SP中收到了上述错误。 (表存储)列MaxWeight,Height,Width,&深度是浮动的。 Anyideas?

 USE [Induction]
 GO
/****** Object:  StoredProcedure [dbo].[usp_GetStorageDetails1]    Script Date: 06/14/2013        14:39:33 ******/
   SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 ALTER PROCEDURE [dbo].[usp_GetStorageDetails1]

@RowID int,
@WarehouseID int,
@query VARCHAR(100),
@sortcol VARCHAR(100),
@sortorder VARCHAR(100),
@total int OUTPUT

  AS
 BEGIN

  Select * into #PAGING FROM
 ( 
  SELECT 
  ROW_NUMBER() OVER (ORDER BY 
CASE WHEN @sortcol='WarehouseID' AND @sortorder = 'asc' THEN W.ID END ASC,
CASE WHEN @sortcol='WarehouseID' AND @sortorder = 'desc' THEN W.ID END DESC,

CASE WHEN @sortcol='Name' AND @sortorder = 'asc'  THEN W.Name END ASC,
CASE WHEN @sortcol='Name' AND @sortorder = 'desc'  THEN W.Name END DESC,

CASE WHEN @sortcol='Name' AND @sortorder = 'asc'  THEN ST.Name END ASC,
CASE WHEN @sortcol='Name' AND @sortorder = 'desc'  THEN ST.Name END DESC,

CASE WHEN @sortcol='Code' AND @sortorder = 'asc'  THEN (ISNULL(S.IdentifierA,'')+ '-' + ISNULL(S.IdentifierB,'') + '-' + ISNULL(S.IdentifierC,'') + '-' + ISNULL(S.IdentifierD,'')+ '-' + ISNULL(S.IdentifierE,''))  END ASC,
CASE WHEN @sortcol='Code' AND @sortorder = 'desc'  THEN (ISNULL(S.IdentifierA,'')+ '-' + ISNULL(S.IdentifierB,'') + '-' + ISNULL(S.IdentifierC,'') + '-' + ISNULL(S.IdentifierD,'')+ '-' + ISNULL(S.IdentifierE,''))  END DESC,

   CASE WHEN @sortcol='Dimension' AND @sortorder = 'asc'  THEN (ISNULL(Height,'')+ 'x' +  ISNULL(Width,'') + 'x' + ISNULL(Depth,'')) END ASC,
CASE WHEN @sortcol='Dimension' AND @sortorder = 'desc'  THEN (ISNULL(Height,'')+ 'x' +  ISNULL(Width,'') + 'x' + ISNULL(Depth,'')) END DESC

) AS rowid
, W.ID
, ST.Name As [Type]
, W.Name As Warehouse
,(ISNULL(S.IdentifierA,'')+ '-' + ISNULL(S.IdentifierB,'') + '-' + ISNULL(S.IdentifierC,'') + '-' + ISNULL(S.IdentifierD,'')+ '-' + ISNULL(S.IdentifierE,'')) AS Code  
,MaxWeight
,S.Height
,S.Width
,S.Depth
,(ISNULL(Height,'')+ 'x' + ISNULL(Width,'') + 'x' + ISNULL(Depth,'')) As Dimension

    from Storage S Left join Warehouse W on S.WarehouseID = W.ID left join StorageType ST on
    S.StorageTypeID = ST.ID  
group by S.ID
        ,W.ID
        ,ST.Name
        ,W.Name
        ,S.IdentifierA
        ,S.IdentifierB
        ,S.IdentifierC
        ,S.IdentifierD
        ,S.IdentifierE
        ,MaxWeight
        ,S.Height
        ,S.Width
        ,S.Depth

 HAVING 
 W.Name LIKE  '%' + @query + '%' 
 OR ST.Name LIKE  '%' + @query + '%') as Listing

Select * from #PAGING where ID=@WarehouseID or rowid =@RowID


 SELECT @total = COUNT(*)  from Storage S Left join Warehouse W on S.WarehouseID = W.ID left join  StorageType ST on S.StorageTypeID= ST.ID    
  WHERE  W.Name LIKE  '%' + @query + '%' 
    OR ST.Name LIKE  '%' + @query + '%'

drop table #PAGING  
END

1 个答案:

答案 0 :(得分:1)

你的isnulls应该是浮动的而不是''空字符串

(ISNULL(Height,0.0)+ 'x' + ISNULL(Width,0.0) + 'x' + ISNULL(Depth,0.0)) As Dimension

我也会检查你的其他isnulls,确保它们返回你想要的值类型。