代码改变世界

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

2012-09-17 17:25  hongjiumu  阅读(2210)  评论(0编辑  收藏  举报
 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是会报错的.