Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 where clause

Author  Topic 

seeker62
Starting Member

40 Posts

Posted - 2013-02-08 : 17:07:13
select *, test.anything as all
from test
where all = 'cant'

gives me an error stateing that it can not find the field all. That field is in the select statement. So how can I make this work.

when i run select *, test.anything from test data appears under the column all

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-02-08 : 17:18:05
where test.anything = 'cant'


Too old to Rock'n'Roll too young to die.
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-08 : 17:19:43
ALL is a keyword - that may be the issue. Try this with the square brackets?
select *, test.anything as all
from test
where [all] = 'cant'


Editing: Strike that. I had missed the alias. Go with what WebFred suggested
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-08 : 23:26:22
quote:
Originally posted by seeker62

select *, test.anything as all
from test
where all = 'cant'

gives me an error stateing that it can not find the field all. That field is in the select statement. So how can I make this work.

when i run select *, test.anything from test data appears under the column all



if you want to use alias

it should be


select *
from
(
select *, test.anything as [all]
from test
)t
where [all] = 'cant'


i would suggest using this approach only if anything is a complex expression and dont want to repeat otherwise use Freds suggestion

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -