我有一个sql查询,执行时会出错
" 无法比较或排序text,ntext和image数据类型,除非使用IS NULL或LIKE运算符。"
查询
SELECT Count(*) AS present,
(SELECT Count(counted)
FROM (SELECT attdate AS counted
FROM gtab85
WHERE attdate >= '01/10/2014'
AND attdate <= '11/10/2014'
GROUP BY attdate) AS derived) AS working,
gtab86.staffname
FROM gtab85 AS A
INNER JOIN gtab86
ON gtab86.staffid = A.userid
WHERE attdate >= '01/10/2014'
AND attdate <= '11/10/2014'
GROUP BY userid,
staffname
当我执行以下部分时
SELECT Count(*) AS present,
(SELECT Count(counted)
FROM (SELECT attdate AS counted
FROM gtab85
WHERE attdate >= '01/10/2014'
AND attdate <= '11/10/2014'
GROUP BY attdate) AS derived) AS working
我以未分类的方式得到结果。请帮我解决这个问题。
答案 0 :(得分:0)
尝试将文本转换为varchar:
select count(*) as present,
(select count(counted)
from (select attdate as counted
from gtab85
where attdate >='01/10/2014' and attdate <='11/10/2014' group by attdate
) as derived
) as working,
convert(varchar(255),gtab86.staffname )
from gtab85 as A
inner join gtab86
on gtab86.staffid=A.userid
where attdate >='01/10/2014' and attdate <='11/10/2014'
group by userid,convert(varchar(255),gtab86.staffname )