MS-SQL 执行一个参数为GUID的存储过程

可能会遇到的错误信息如下:

Error converting data type varchar to uniqueidentifier

conversion failed when converting from a character string to uniqueidentifier

 

你先需要将字符串转换为uniqueidentifier类型.

 

举例如下:

declare @guid uniqueidentifier 
select @guid = CAST('16d85cfe-360f-44af-bc79-33bc1e89b698' as uniqueidentifier)
exec proc_GetSiteUsage @guid

 

如果需要新创建一个GUID, 可以这样做:

declare @guid uniqueidentifier
set @guid= NEWID()
print 'Value of @guidis: '+ CONVERT(varchar(255), @guid)

 

 

参考:

Generate GUID (Unique Identifier) in SQL Server

http://www.dotnetspider.com/resources/4866-Generate-GUID-Unique-Identifier-SQL-Server.aspx

failed to convert parameter value from string to guid

http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/b3690c51-32fd-42cf-8c40-78407b9c4cc0

 

关于如何使用存储过程获得数据, 可以参考

http://www.informit.com/articles/article.aspx?p=31283&seqNum=4

关于CAST和Convert的区别, 可以参考

http://www.informit.com/articles/article.aspx?p=31283&seqNum=4

posted on   中道学友  阅读(3378)  评论(2编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律

导航

< 2010年2月 >
31 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 1 2 3 4 5 6
7 8 9 10 11 12 13

技术追求准确,态度积极向上

点击右上角即可分享
微信分享提示