PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
RE: sql where question
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
RE: sql where question
![]() |
RE: sql where question |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

