From: nLL on
-snip-
if
(@TotalInTodayFromSameIp<10)
and (@PublisherLastEranedDifferance > 10)
and (NOT @PublisherLastInAgent=(a)browser)
and (NOT @PublisherLastInIp=(a)ip)
and (@selectedid is not null)
BEGIN
-snip

above IF runs query below BEGIN when all matches (obviously)
i want to make

(NOT @PublisherLastInAgent=(a)browser)
(NOT @PublisherLastInIp=(a)ip)

NOT mandatory IF @PublisherLastEranedDifferance > 10


I believe i should add OR somewhere but I'm getting confused.
From: dave ballantyne on
If you're haveing trouble writing it now , you're have trouble
understanding it when you come to look at it again in X years time.

Break it down to nested ifs, itll be best in the long run

Dave


nLL wrote:
> -snip-
> if
> (@TotalInTodayFromSameIp<10)
> and (@PublisherLastEranedDifferance > 10)
> and (NOT @PublisherLastInAgent=(a)browser)
> and (NOT @PublisherLastInIp=(a)ip)
> and (@selectedid is not null)
> BEGIN
> -snip
>
> above IF runs query below BEGIN when all matches (obviously)
> i want to make
>
> (NOT @PublisherLastInAgent=(a)browser)
> (NOT @PublisherLastInIp=(a)ip)
>
> NOT mandatory IF @PublisherLastEranedDifferance > 10
>
>
> I believe i should add OR somewhere but I'm getting confused.
From: Erland Sommarskog on
nLL (no(a)onehere.nll) writes:
> -snip-
> if
> (@TotalInTodayFromSameIp<10)
> and (@PublisherLastEranedDifferance > 10)
> and (NOT @PublisherLastInAgent=(a)browser)
> and (NOT @PublisherLastInIp=(a)ip)
> and (@selectedid is not null)
> BEGIN
> -snip
>
> above IF runs query below BEGIN when all matches (obviously)
> i want to make
>
> (NOT @PublisherLastInAgent=(a)browser)
> (NOT @PublisherLastInIp=(a)ip)
>
> NOT mandatory IF @PublisherLastEranedDifferance > 10

This may be what you are looking for:

if @TotalInTodayFromSameIp <10 AND
@selectedid is not null AND
(@PublisherLastEranedDifferance > 10 OR
@PublisherLastInAgent <> @browser AND
@PublisherLastInIp <> @ip)

I removed unneeded parens and also replace NOT = with <>, to make it a
little easier.



--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
From: nLL on
dave ballantyne wrote:
> If you're haveing trouble writing it now , you're have trouble
> understanding it when you come to look at it again in X years time.
>
> Break it down to nested ifs, itll be best in the long run
>
> Dave
>
>
> nLL wrote:
>> -snip-
>> if
>> (@TotalInTodayFromSameIp<10)
>> and (@PublisherLastEranedDifferance > 10)
>> and (NOT @PublisherLastInAgent=(a)browser)
>> and (NOT @PublisherLastInIp=(a)ip)
>> and (@selectedid is not null)
>> BEGIN
>> -snip
>>
>> above IF runs query below BEGIN when all matches (obviously)
>> i want to make
>>
>> (NOT @PublisherLastInAgent=(a)browser)
>> (NOT @PublisherLastInIp=(a)ip)
>>
>> NOT mandatory IF @PublisherLastEranedDifferance > 10
>>
>>
>> I believe i should add OR somewhere but I'm getting confused.


i done it with nested ifs but was trying to sort it in a one if
From: nLL on
Erland Sommarskog wrote:
> nLL (no(a)onehere.nll) writes:
>> -snip-
>> if
>> (@TotalInTodayFromSameIp<10)
>> and (@PublisherLastEranedDifferance > 10)
>> and (NOT @PublisherLastInAgent=(a)browser)
>> and (NOT @PublisherLastInIp=(a)ip)
>> and (@selectedid is not null)
>> BEGIN
>> -snip
>>
>> above IF runs query below BEGIN when all matches (obviously)
>> i want to make
>>
>> (NOT @PublisherLastInAgent=(a)browser)
>> (NOT @PublisherLastInIp=(a)ip)
>>
>> NOT mandatory IF @PublisherLastEranedDifferance > 10
>
> This may be what you are looking for:
>
> if @TotalInTodayFromSameIp <10 AND
> @selectedid is not null AND
> (@PublisherLastEranedDifferance > 10 OR
> @PublisherLastInAgent <> @browser AND
> @PublisherLastInIp <> @ip)
>
> I removed unneeded parens and also replace NOT = with <>, to make it a
> little easier.
>
>
>

Thank you! Appreciated