SQL从数据类型 nvarchar 转换为 bigint 时出错解决方案


--添加表值函数
1
ALTER function [dbo].[func_splitstring] 2 (@str nvarchar(max),@split varchar(10)) 3 returns @t Table (id varchar(100)) 4 as 5 begin 6 declare @i int 7 declare @s int 8 set @i=1 9 set @s=1 10 while(@i>0) 11 begin 12 set @i=charindex(@split,@str,@s) 13 if(@i>0) 14 begin 15 insert @t(id) values(substring(@str,@s,@i-@s)) 16 end 17 else begin 18 insert @t(id) values(substring(@str,@s,len(@str)-@s+1)) 19 end 20 set @s = @i + 1 21 end 22 return 23 end

ALTER PROCEDURE [dbo].[GetStudentListByStudentId]
@StudentId nvarchar(500)
as
BEGIN
--调用表值函数转换类型
select * from Student where StudentId in(SELECT cast(id as int) StudentId FROM dbo.func_splitstring(@StudentId,','))
end
 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM