July 3, 2006 at 6:51 am
- when 'AFFILIATES' is passed as the parameter, only those records with an int value in brokeraffiliation.affiliatedcompanyid are returned;
- when 'NON-AFFILIATES' is passed as the parameter, only those records with a NULL value in brokeraffiliation.affiliatedcompanyid are returned;
- when 'BOTH' is passed as the parameter, all records are returned.
and brokeraffiliation.affiliatedcompanyid =
case when @BrokerType = 'NON-AFFILIATED' then null
case when @BrokerType = 'AFFILIATES' then not null
else affiliation.affiliatedcompanyid
end
July 3, 2006 at 9:25 am
Instead of a CASE statement, try this in your where clause instead:
((@BrokerType = 'NON_AFFILIATED' and affiliation.affiliatedcompanyid is null)
or (@BrokerType = 'AFFILIATES' and affiliation.affiliatedcompanyid is not null)
or (@BrokerType = 'BOTH'))
HTH,
Lynn
July 3, 2006 at 9:44 am
the correct syntax for not null check is 'IS NOT NULL' and not ' = not null', hence the syntax error.
I would think the easiest approach would be to use function ISNUMERIC instead of NULL and NOT NULL so
and ISNUMERIC(brokeraffiliation.affiliatedcompanyid
) =case when @BrokerType = 'NON-AFFILIATED' then 0
else BETWEEN 0 and 1
end
July 3, 2006 at 10:04 am
Remember that NUMERIC has some drawbacks like those one posted from here: http://www.aspfaq.com/show.asp?id=2390
HTH, Jens Suessmeyer.
---
---
July 4, 2006 at 12:45 pm
So instead of answering his question you flame him on syntax?
July 4, 2006 at 9:56 pm
I have to agree with Ken, Joe. After reading your response
above plus several others, you are down right mean and unhelpful.
You may be a smart SQL Server Guru and a published author, but
you totally lack any compassion or sense of tact when dealing with
others who may not have as much experience as you.
Try being helpful and supportive of others and help guide them on
how to write better SQL code instead of flaming them and condemning
them for how they may be writing code.
July 5, 2006 at 1:52 am
To those that helped, many thanks.
To those that chose to flame... well, my status on this forum is 'Newbie'. That's exactly what I am as far as SQL is concerned.
>> you seem to want to keep writing procedural code << >> you are missing the entire SQL model and working with a procedural file system in your head <<
I'm an OO (Java / C#) coder by trade, stepping in to write some stored procedures for a project that's slipping. I'm learning as I go.
>> You might want to consider shorter encoding that are less subjec (sic) to typographical. <<
These values have already been decided for me and cannot be changed, as has the database schema (apologies if this terminology is incorrect btw), which has been inherited from a 3rd party source.
Now while I appreciate that it may be frustrating for a guru to see what he or she considers to be basic errors in a question, it is equally frustrating for a newbie to the language to be flamed and - I'm sorry to say this - patronised - for having the temerity to ask such a question.
In many years of using the web this is the first time I've felt the need to defend myself in this way... way to welcome a new member of the community.
July 5, 2006 at 7:22 am
Well said Keith.
July 5, 2006 at 8:06 am
Welcome Keith,
Don't let Joe Celko's comments upset you. Some people are bound and determined to always speak down to everyone – they like to make themselves feel important. That is the only way they can inflate their ego - no one else will do it for them.
Hey Joe, now that you have learned so much about SQL, why don’t you take a Communications Class and learn how to be an EFFECTIVE communicator – you have a ways to go buddy.
I'll bet Joe is 5' 9" and 140 lbs. (Hitler complex).
By the way, Joe has ONLY contributed 299 posts out of the 289,958 we have. If he went away, we wouldn't even miss him.
Hang around Keith. Don't let BIG BAD Joe scare you away.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply