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 well 🙂 Thanks much!
Agh... I wouldn't create a view for such a thing. Just create a subquery and use the criteria against that.
--Jeff Moden
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';
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply