July 23, 2003 at 8:12 am
The following query is supposed to increment a count everytime the condition is true..im just not sure about the syntax and the order of the statements etc........Basically, i want to read through the table and everytime the condition is met I want to increment the count..........Can an inner join beused in conjunction with an IF statement, if not are there any other ways of doing this? Thanks guys
declare @count int
select @count = 0
select t2.cust_id, t1.cust_id from unique_cust t1 INNER JOIN unique_cust t2
if (t1.dup_code = t2.dup_code)
begin
select @count = @count+1
end
If riding in a plane is flying, then riding in a boat must be swimming. To experience the element, get out of the vehicle. Skydive!
If riding in a plane is flying, then riding in a boat must be swimming. To experience the element, get out of the vehicle. Skydive!
July 23, 2003 at 8:25 am
You need an ON clause for your JOIN, plus, you don't need to increment a counter...
DECLARE @counter INT
SELECT COUNT(*) = @counter
FROM unique_cust t1
INNER JOIN unique_cust t2 ON t1.key_field = t2.key_field
WHERE t1.dup_code = t2.dup_code
July 23, 2003 at 3:29 pm
Just a small thingy in the query of jpipes. You need to switch the Count(*) = @counter to @counter = count(*)
July 24, 2003 at 6:32 am
Thanks, NPeeters!!
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply