View Full Version : Grid View and use of 'AS' in query.

03-12-2011, 08:19 AM
This is my query:

SELECT [name1], [name2], [mail_street1], [mail_street2], [mail_city], [mail_state], [mail_zip], [phone], [website] FROM [flat_list] WHERE (([mail_state] = 'NJ') AND ([rl] = 'x' OR [rs] = 'x')) ORDER BY [name1], [name2]

This is what I am trying to accomplish: [mail_street1], [mail_street2], [mail_state], [mail_zip] (Combine into one field).

I am working on a couple of assumptions right now. One being that when I use the 'AS' the Grid View will be smart enough to reformat itself to reflect the fact that there is data that used to be in multiple columns that is now one. Two is that the use of 'AS' is actually possible with this query. I am honestly quite lost as to how to implement the 'AS' to combine said data. Can someone provide some input on this? Thank you. :eek:

04-04-2011, 07:51 PM
The answer may be different for other database but for SQL Server you probably want something like this:

select name1, name2, mail_street1 + ' ' + mail_street2 + ' ' + mail_state + ' ' + mail_zip as [Mailing Address]... etc.

You can keep the square brackets as in your original example, but they are only necessary if your field names are reserved words, or they contain spaces, or other punctuation characters.

04-23-2011, 01:51 PM
I am really can't exact understand your topic.But i have one solution that you can replace your query with this.
SELECT [name1] as Firstname, [name2] as Lastname, [mail_street1] a Email_Address, [mail_street2], [mail_city] as City, [mail_state] as State, [mail_zip] as Zip, [phone] as Phone, [website] FROM [flat_list] WHERE (([mail_state] = 'NJ') AND ([rl] = 'x' OR [rs] = 'x')) ORDER BY [name1], [name2]