SQL。如何将变量转换为字符串?

灰烬一

我试图用RAISERROR(Cast (select @HostelId as varchar(50))Raiserror显示我的变量。但是我不知道如何将sql变量转换为字符串。

Declare @HostelId int=0;
Declare @Hostels Cursor;

SET @Hostels  = cursor for select Hostel.HostelCode
From  Hostel

Open @Hostels 
While @@FETCH_STATUS = 0
Fetch next from @Hostels into @HostelId
Begin 
    RAISERROR(Cast (select @HostelId as varchar(50)), 0,0);
End
Close @Hostels
瓦桑

对消息字符串参数使用格式字符串,如下所示:

RAISERROR('%d', 0,0, @HostelId);

参考

Open @Hostels
Fetch next from @Hostels into @HostelId
While @@FETCH_STATUS = 0
Begin 
    RAISERROR('%d', 0,0, @HostelId);
    Fetch next from @Hostels into @HostelId
End
Close @Hostels

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章