Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select Th.groupY,
Th.CDPY,
Bh.fold
as count(*)
from dbo.tblTraceHeaders as Th
left outer join dbo.tblBinaryHeaders as Bh on Th.fileID=Bh.fileID where Th.fileID in (1,5,3)
Group By Th.groupY,Th.CDPY,Bh.fold
having
count(*)> 1 and Th.fileID in (1,5,3)
Posted

Bh.fold as Count(*) can't work because of the use of the keyword.

You can turn this into an implicit column header by either adding square braces or single quotes:

SQL
select Th.groupY,
    Th.CDPY,
    Bh.fold as [count(*)]
from dbo.tblTraceHeaders as Th
    left outer join dbo.tblBinaryHeaders as Bh on Th.fileID=Bh.fileID where Th.fileID in (1,5,3)
Group By Th.groupY,Th.CDPY,Bh.fold
having
    count(*)> 1 and Th.fileID in (1,5,3)


Is this not what you intended?

maybe you want to use the count(*) instead of naming the column such?

SQL
select Th.groupY,
    Th.CDPY,
    Bh.fold, --missing comma
    count(*) as [count(*)] -- add a count and name it count(*)
from dbo.tblTraceHeaders as Th
    left outer join dbo.tblBinaryHeaders as Bh on Th.fileID=Bh.fileID where Th.fileID in (1,5,3)
Group By Th.groupY,Th.CDPY,Bh.fold
having
    count(*)> 1 and Th.fileID in (1,5,3)


let me know if neither of these are what you need ^_^
 
Share this answer
 
v2
First : you put as after the aggregate or column name -> count(*) as mycount

Second : put the column name you want to count in the function and not * -> count(columnname)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900