Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2003

    Unanswered: IF'sand INNER JOINS

    The following query is supposed to increment a count everytime the condition is 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)
    select @count = @count+1
    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!

  2. #2
    Join Date
    Jul 2003
    Never ever heard of this before in any database engine!

    I know that you can use the function case in the select stmt, but it will not solve ur problem.
    SELECT 'Price Category' =
    WHEN price IS NULL THEN 'Not yet priced'
    WHEN price < 10 THEN 'Very Reasonable Title'
    WHEN price >= 10 and price < 20 THEN 'Coffee Table Title'
    ELSE 'Expensive book!'
    FROM titles
    ORDER BY price

    Note 1: You can use it only to return a computed value within the same table.

    Note 2: Read more about the COMPUTE Clause in the select stmt, but I already know that it will not solve it.

    I suggest implementing a cursor to do ur work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts