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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 where clause
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

seeker62
Starting Member

40 Posts

Posted - 02/08/2013 :  17:07:13  Show Profile  Reply with Quote
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

Edited by - seeker62 on 02/08/2013 17:09:45

webfred
Flowing Fount of Yak Knowledge

Germany
8781 Posts

Posted - 02/08/2013 :  17:18:05  Show Profile  Visit webfred's Homepage  Reply with Quote
where test.anything = 'cant'


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

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/08/2013 :  17:19:43  Show Profile  Reply with Quote
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

Edited by - James K on 02/08/2013 17:23:37
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 02/08/2013 :  23:26:22  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000