PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET RE: sql where question

Reply

RE: sql where question

 
Thread Tools Rate Thread
Old 27-12-2006, 06:10 AM   #1
=?Utf-8?B?TWFuaXNoIEJhZm5h?=
Guest
 
Posts: n/a
Default RE: sql where question


Hi,
You can use Case Statemant.The basic syntax for a simple CASE expressions is
shown below:

CASE expression
WHEN expression1 THEN expression1
[[WHEN expression2 THEN expression2] [...]]
[ELSE expressionN]
END

In you case it would be something like this:
SELECT Admin,fieldslist from tablename
where = CASE Admin
WHEN Admin = Y OR N THEN 'some query'
WHEN Admin = N THEN 'some other query'
ELSE 'Unknown'
END

You can modify this query according to your requirement.
Hope this helps you out.

Thanks and Regards,
Manish Bafna.
MCP and MCTS.



"MarkAurit" wrote:

> Ive a char(1) column (lets call it Admin) that can be 'Y' or 'N'.
> In one of my queries I need to treat non-admins is those with
> Admin='N', and admins as those with (Admin='Y' or Admin='N'). Easy
> enough if Im buiding the query dynamically, but Im using a stored procedure
> and its gotten ugly enough that Ive used kludges like:
> if (admin='Y')
> begin
> do query with (admin='Y' or admin='N')
> end
> else
> begin
> do query with (admin='N')
> end
> which virtually duplicates the code, sor of like the bol "if .. else"
> example B.
> But I really dont like the duplicated code.
> Ideas? Thanks, Mark

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off