sql语句语法出错,帮忙看下好吗?

来源:百度知道 编辑:UC知道 时间:2024/06/24 13:05:46
select count(*) from table where procategory=N(select distinct procategory from table where typeid='1')

语法错在那个 N 那里,因为N后边括号返回值有中文或韩文,如果不加N的话程序不会报错,但是sql语句运行后结果是不正确。
麻烦看下应该怎么改,谢谢啦!!
下边几位好像没注意到我说的韩文,我加N (nvarchar)让它能正常显示韩文值,运行结果才会正常,看下边2个结果不一样的:

select count(*) from prokormsg where procategory = N'핫피스' 返回 10 检索正确
select count(*) from prokormsg where procategory = '핫피스' 返回 0 检索错误
---------------------------------------------------------------------------------------------
select count(*) from prokormsg where procategory like N'핫피스' 返回 10 检索正确
select count(*) from prokormsg where procategory like '핫피스' 返回 0 检索错误
---------------------------------------------------------------------------------------------
select count(*) from prokormsg where procategory in N'핫

select count(*) from table where procategory like (select distinct procategory from table where typeid='1')

create proc Procategory_Count @Typeid char(1)
as
create table #tmp(tcategory nvarchar(50))
insert #tmp(tcategory)
select distinct procategory from table where typeid=@Typeid

select count(*) from table(nolock) ,#tmp where procategory=tcategory
go

select count(*) from table where procategory=N(select distinct procategory from table where typeid='1')

重复去掉

select count(distinct procategory) from table where typeid='1'

select count(*) from table where procategory in (select distinct procategory from table where typeid='1')
应该要这样吧.

把 = 号改成in