当前位置: 代码迷 >> Sql Server >> SQL查询时出现“将字符串变换为 uniqueidentifier 时失败”
  详细解决方案

SQL查询时出现“将字符串变换为 uniqueidentifier 时失败”

热度:63   发布时间:2016-04-27 11:35:19.0
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 [email protected]'
  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 [email protected]'
  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 [email protected]') 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 [email protected]') b on 1=1


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


------解决方案--------------------
SQL code
--你的参数现在是这个样子的declare @p varchar(30)set @[email protected]'select @p/*@c.CustomerID*/--应该是这个样子的declare @p1 varchar(36)set @p1=newid()select @p1/*AE9508EE-24D1-4AF2-9285-18373B*/
------解决方案--------------------
探讨
c.CustomerID是uniqueidentifier类型的...