Link to home
Create AccountLog in
Avatar of Kiran_M
Kiran_M

asked on

SQL Server 2005 - Using the derived value in the Select WHERE Condition

I am trying to use the derived value in the Select Statement Where condition as shown below :



Select  field a, field b,
  GetSomelList(tableA.field z) as Lista,   /* Where GetSomeList is a function
field c
from  tableA 
where  some condition AND  Lista <> ','
 
I get the error Lista is not a "table column' as expected because it is dervied 
 value and not a table column.
 
I can do this
 
Select  field a, field b,
  GetSomelList(tableA.field z) as Lista,  /* Where GetSomeList is a function
field c
from  tableA 
where  some condition AND  GetSomelList(tableA.field z)  <> ','
 
Is there a better way of do this  instead of calling the same function twice in the select statement.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of aaronakin
aaronakin
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Kiran_M
Kiran_M

ASKER

aaronkin suggestion worked great for my case.  Mark_wills - thanks a lot for all the alternate solutions for other scenerios.