0

For example, my query is something like:

SELECT fullName = firstName + ' ' + middleName + ' ' + lastName,
streetAddress = address1
FROM Person

How would I be able to reference fullName directly without having to type out first+middle+last again? If I just added "WHERE fullName = 'John X Doe'", i get the error that fullName is an invalid column.

I've tried throwing it into a variable

SELECT @fullNameVar = firstName + ' ' + middleName + ' ' + lastName,
fullName = @fullNameVar
streetAddress = address1
FROM Person
WHERE @fullNameVar = 'John X Doe'

but I cannot use a select statement to set a variable when I am also retrieving other data.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by faintfascinatio
2
SELECT * FROM (
  SELECT firstName + ' ' + middleName + ' ' + lastName AS fullName, address1 AS streetAddress
  FROM Person
) P
WHERE fullName = 'John X Doe'

Edited by pritaeas: n/a

0
SELECT * FROM (
  SELECT firstName + ' ' + middleName + ' ' + lastName AS fullName, address1 AS streetAddress
  FROM Person
) P
WHERE fullName = 'John X Doe'

Exactly what I was looking for. Thanks!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.