日期:2014-05-17  浏览次数:20951 次

SQL查询时出现“将字符串转换为 uniqueidentifier 时失败”。
select a.CustomerName,a.boy,b.girl from 
  (select c.CustomerName,count(*) as boy from tb_masEmPersonalInfo a 
  left join tb_masEmployeeEmployer b on a.EmPersonalInfoID=b.EmPersonalInfoID
  left join tb_masCustomer c on b.CustomerID=c.CustomerID
  where a.Disabled=0
  and b.EwStatus in ('A','N') 
  and a.GenderID=1
  and c.CustomerID='@c.CustomerID'
  group by c.CustomerName) a 
  left join
  (select c.CustomerName,count(*) as girl from tb_masEmPersonalInfo a 
  left join tb_masEmployeeEmployer b on a.EmPersonalInfoID=b.EmPersonalInfoID
  left join tb_masCustomer c on b.CustomerID=c.CustomerID
  where a.Disabled=0
  and b.EwStatus in ('A','N') 
  and a.GenderID=2
  and c.CustomerID='@c.CustomerID'
  group by c.CustomerName) b on a.CustomerName=b.CustomerName
   
  union

  select '总计' as CustomerName,a.boy as 男,b.girl as 女 from 
  (select count(*) as boy from tb_masEmPersonalInfo a 
  left join tb_masEmployeeEmployer b on a.EmPersonalInfoID=b.EmPersonalInfoID
  left join tb_masCustomer c on b.CustomerID=c.CustomerID
  where a.Disabled=0
  and b.EwStatus in ('A','N') 
  and a.GenderID=1
  and c.CustomerID='@c.CustomerID') a 
  left join
  (select count(*) as girl from tb_masEmPersonalInfo a 
  left join tb_masEmployeeEmployer b on a.EmPersonalInfoID=b.EmPersonalInfoID
  left join tb_masCustomer c on b.CustomerID=c.CustomerID
  where a.Disabled=0
  and b.EwStatus in ('A','N') 
  and a.GenderID=2
  and c.CustomerID='@c.CustomerID') b on 1=1


将字符串转换为 uniqueidentifier 时失败。


------解决方案--------------------
SQL code

--你的参数现在是这个样子的
declare @p varchar(30)
set @p='@c.CustomerID'
select @p
/*
@c.CustomerID
*/

--应该是这个样子的
declare @p1 varchar(36)
set @p1=newid()
select @p1
/*
AE9508EE-24D1-4AF2-9285-18373B
*/

------解决方案--------------------
探讨
c.CustomerID是uniqueidentifier类型的...