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