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/archive/2012/09/17/2689059.html
相关资源:SQL Server 2008宝典--详细书签版(第1/2部分)