Dynamic WHERE statement

Posted: 01-28-2005, 11:31 PM
If I pass a variable to @Cost_Center that is 'SMS', 'SMP' OR 'ALL'
'ALL' will return records that have either 'SMS' or 'SMP' in them.
Now I am using an if statement that has the entire SQL statement in the body
of the
conditional.

I tried this

Where

IF (@Cost_Center = 'All')

Begin

code...
and i.cost_center in ('SMS','SMP')

End

ELSE

Begin

code...
and i.cost_center = @Cost_Center

End


Thanks
Jim


Dynamic WHERE statement


Responses to "Dynamic WHERE statement"

Admiral Q
Guest
Posts: n/a
 
Re: Dynamic WHERE statement
Posted: 01-29-2005, 12:10 AM
In case you haven't figured it out, this is a "windows XP setup and
deployment group" and not a "how to code SQL2k group". Your best bet is to
repost in one of the many SQL newsgroups for the "gurus" there to answer
your question. ;-)

--
Star Fleet Admiral Q @ your service!


"Jim Warren" <[email protected]> wrote in message
news:[email protected]..
> If I pass a variable to @Cost_Center that is 'SMS', 'SMP' OR 'ALL'
> 'ALL' will return records that have either 'SMS' or 'SMP' in them.
> Now I am using an if statement that has the entire SQL statement in the
body
> of the
> conditional.
>
> I tried this
>
> Where
>
> IF (@Cost_Center = 'All')
>
> Begin
>
> code...
> and i.cost_center in ('SMS','SMP')
>
> End
>
> ELSE
>
> Begin
>
> code...
> and i.cost_center = @Cost_Center
>
> End
>
>
> Thanks
> Jim
>
>

Jim Warren
Guest
Posts: n/a
 
Re: Dynamic WHERE statement
Posted: 01-29-2005, 12:19 AM
Sorry about that, it was a very long day, about 2pm time slowed noticeably
"Admiral Q" <Star_Fleet_Admiral_Q(NOSPAM)@(SPAMNOT)hotmail.com > wrote in
message news:u4$[email protected]..
> In case you haven't figured it out, this is a "windows XP setup and
> deployment group" and not a "how to code SQL2k group". Your best bet is
> to
> repost in one of the many SQL newsgroups for the "gurus" there to answer
> your question. ;-)
>
> --
> Star Fleet Admiral Q @ your service!
>
>
> "Jim Warren" <[email protected]> wrote in message
> news:[email protected]..
>> If I pass a variable to @Cost_Center that is 'SMS', 'SMP' OR 'ALL'
>> 'ALL' will return records that have either 'SMS' or 'SMP' in them.
>> Now I am using an if statement that has the entire SQL statement in the
> body
>> of the
>> conditional.
>>
>> I tried this
>>
>> Where
>>
>> IF (@Cost_Center = 'All')
>>
>> Begin
>>
>> code...
>> and i.cost_center in ('SMS','SMP')
>>
>> End
>>
>> ELSE
>>
>> Begin
>>
>> code...
>> and i.cost_center = @Cost_Center
>>
>> End
>>
>>
>> Thanks
>> Jim
>>
>>
>
>

 
LinkBack Thread Tools Display Modes
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Statement in need of HELP MicheleY Mac Office Excel 3 11-11-2006 05:35 PM
Retraction of Statement` John Kelly Windows XP Movie Maker 0 02-12-2005 02:29 PM
Exception statement DMMartin58 Windows XP Help & Support 1 01-21-2004 03:27 AM
[O.T.] SCO's mission statement Charles Linux / Unix 0 01-17-2004 03:55 PM
PATH statement Dick Adams Customize Windows XP 2 07-20-2003 03:37 PM