如何解决sql server2008:将字符串转换为 uniqueidentifier 时出现语法错误

 declare @parentKey char(36)
 
  set @parentKey='B4B519EF-13F9-4F85-A382-21362F337D9D'
  select [Pro_ProductCategory].[CategoryName]+'('+
    cast((select COUNT(1)from Pro_ProductMST where ProductModelKey in (select ModelKey from Pro_ProductModel where CategoryKey=[Pro_ProductCategory].CategoryKey)) as varchar)
+')' as 'CategoryStatic'
    from [Pro_ProductCategory] where [parentKey]=cast(@parentKey as uniqueidentifier)
    

这里的关键是要写上36这个长度,不然使用varchar是会报错的.

原文地址:https://www.cnblogs.com/hongjiumu/p/2689059.html