Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count a query

Status
Not open for further replies.

excalibur78

IS-IT--Management
Jan 3, 2001
66
US
I can't seem to get a record count of this select to work:

SELECT [Masterfile].[Store #], [Masterfile].[PC/LAN1 Start]
FROM [Masterfile]
LEFT JOIN [Inventory Tracking]
ON [Masterfile].[Store #] = [Inventory Tracking].[Store #]
WHERE [Masterfile].[PC/LAN1 Start] >= '4/29/2003' AND [Masterfile].[PC/LAN1 Start] <= GetDate() AND [Inventory Tracking].[BOM Ship Date] Is Null AND [Inventory Tracking].[Store #] Is Null and [Masterfile].[Store #] <> '1020' and [Masterfile].[Store #] <> '926' and [Masterfile].[Store #] <> '6314' and [Masterfile].[Store #] <> '1027'
ORDER BY [Masterfile].[PC/LAN1 Start]

Any ideas would be great.


Thanks,

David
 
What is the database? I have found that for example Pervasive doesn't support the recordcount thing. Also how are you connecting to the database?
 
usually u need group by for counting.May I know which column you want to count.
Your query doesnt seem to have problem.Are you getting any error msgs?
What kind of result you want to get?
 
Anything will work for record count. [Masterfile].[Store #] would be the logical choice. What I was trying to do is somethink like this:

Select Count(*) from (SELECT [Masterfile].[Store #], [Masterfile].[PC/LAN1 Start]
FROM [Masterfile]
LEFT JOIN [Inventory Tracking]
ON [Masterfile].[Store #] = [Inventory Tracking].[Store #]
WHERE [Masterfile].[PC/LAN1 Start] >= '4/29/2003' AND [Masterfile].[PC/LAN1 Start] <= GetDate() AND [Inventory Tracking].[BOM Ship Date] Is Null AND [Inventory Tracking].[Store #] Is Null and [Masterfile].[Store #] <> '1020' and [Masterfile].[Store #] <> '926' and [Masterfile].[Store #] <> '6314' and [Masterfile].[Store #] <> '1027'
ORDER BY [Masterfile].[PC/LAN1 Start])
 
Shouldn't it be something like this????
(Don't know what you need the left join for)

Select Count(*)
FROM [Masterfile] LEFT JOIN [Inventory Tracking]
ON [Masterfile].[Store #] = [Inventory Tracking].[Store #]
WHERE [Masterfile].[PC/LAN1 Start] >= '4/29/2003'
AND [Masterfile].[PC/LAN1 Start] <= GetDate()
AND [Inventory Tracking].[BOM Ship Date] Is Null
AND [Inventory Tracking].[Store #] Is Null
AND [Masterfile].[Store #] <> '1020'
OR [Masterfile].[Store #] <> '926'
OR [Masterfile].[Store #] <> '6314'
OR [Masterfile].[Store #] <> '1027'


I believe you should use OR instead of AND in your [Masterfile].[Store #]

Regards,

Atomic Wedgie
 
Maybe you should give some example.Because your query doesnt have any problem.Or you should explain more detailly about the condition and also the desired result
 
Thanks everyone. I modified Atomic's and think I got it working right.


Thanks,


David
 
Unless I misunderstand, this will do it:

Code:
SELECT COUNT(*)
FROM [Masterfile]
LEFT JOIN [Inventory Tracking]
ON [Masterfile].[Store #] = [Inventory Tracking].[Store #]
WHERE [Masterfile].[PC/LAN1 Start] >= '4/29/2003' AND [Masterfile].[PC/LAN1 Start] <= GetDate() AND [Inventory Tracking].[BOM Ship Date] Is Null AND [Inventory Tracking].[Store #] Is Null and [Masterfile].[Store #] <> '1020' and [Masterfile].[Store #] <> '926' and [Masterfile].[Store #] <> '6314' and [Masterfile].[Store #] <> '1027'

--James
 
Did you use OR instead of AND in your [Masterfile].[Store #] or is AND the right way. I always get those two mixed up.
 
Final select was:

Select Count(*)
FROM [Masterfile] LEFT JOIN [Inventory Tracking]
ON [Masterfile].[Store #] = [Inventory Tracking].[Store #]
WHERE [Masterfile].[PC/LAN1 Start] >= '4/29/2003'
AND [Masterfile].[PC/LAN1 Start] <= GetDate()
AND [Inventory Tracking].[BOM Ship Date] Is Null
AND [Inventory Tracking].[Store #] Is Null
AND [Masterfile].[Store #] <> '1020'
AND [Masterfile].[Store #] <> '926'
AND [Masterfile].[Store #] <> '6314'
AND [Masterfile].[Store #] <> '1027'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top