September 11, 2009 at 10:34 am
select 'a' as char1, 'b' as char2 where char1 != 'a'
In MySQL I was always able to do this however it doesn't appear to work with MS SQL. I've tried using where and having. Can I not used a "as" named column in a where statement? One of the selects that I'm working with needs to do some calculations in the columns being selected area and I'd hate to have to paste that whole calculation into the where statement as well.
I'm sure I'm just doing something wrong here, serves me right for trying to get something done before coffee has kicked in.
September 11, 2009 at 10:59 am
September 11, 2009 at 12:44 pm
Perfect. That answered my question. I wish it would allow the use of the alias in the where clause though but oh well Thanks much!
September 11, 2009 at 9:49 pm
razmage (9/11/2009)
Perfect. That answered my question. I wish it would allow the use of the alias in the where clause though but oh wellThanks much!
Agh... I wouldn't create a view for such a thing. Just create a subquery and use the criteria against that.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 12, 2009 at 11:37 pm
To illustrate Jeff's point:
SELECT SQ.char1, SQ.char2
FROM (
SELECT char1 = 'a',
char2 = 'b'
) SQ
WHERE SQ.char1 'a';
-- OR
;WITH SQ (char1, char2) AS (SELECT 'a', 'b')
SELECT SQ.char1, SQ.char2
FROM SQ
WHERE SQ.char1 'a';
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy