Conversion failed when converting the nvarchar value 'Internet Explorer 3 original' to data type int

前端 未结 2 663
一整个雨季
一整个雨季 2021-01-15 02:34

In SQL Server 2008 (TSQL), I\'ve created a stored procedure like this:

CREATE PROCEDURE SP_1_10_2
AS
declare @mostValuableBook nvarchar(255)
SELECT @mostValu         


        
2条回答
  •  -上瘾入骨i
    2021-01-15 03:15

    You can also create a function to return the value you desire instead of relying on numeric return codes. SQL Functions come in quite handy. See example below which returns the last name with the highest client id using the LIKE operator

    Use MYDB
    GO
    
    CREATE Function fn_LastClientIdByName
    (
    @nameLike NVARCHAR(10)
    )
    RETURNS NVARCHAR(100)
    AS 
    
    BEGIN
    DECLARE @result nvarchar(100)
    DECLARE @clientName NVARCHAR(100)
    
    SELECT top 1  @clientName = [clientLast] + ' ' + [clientFirst]   
    FROM [dbo].[duiClientOnly]
    WHERE clientLast like @nameLike + '%'
    order by clid desc
    
    select @result = @clientName
    return @result
    END
    

提交回复
热议问题