Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using 'AS' in SQL statements

Status
Not open for further replies.

cawthor

Programmer
May 31, 2001
89
US
Hi,

I have the following SQL statement:

SELECT VAL1 + ISNULL(VAL2, '') AS ALIAS FROM TABLE1

This is concatenating 2 fields in my returned data. In my ASP Code how do I reference the above value? Eg: RS.Fields("ALIAS") returns an 'Exception occured' error.

Thanks...
Rich.
 
What happens if you refer to the field by index? Eg: RS(0)
 
it should be the same datatype.
select convert(char(3),123)+'456'output:123456
select 123+456 output:579
 
RS(0) still gives me the exception error. Both fields are text so there's no conflicting data types.
 
Why not just concat them on the client end?

SELECT VAR1, VAR2 FROM table
myVar = RS(0) & RS(1)

Or is the null a problem?
 
yeah I think you're right. I was concat them in the statement because I was also grouping by this contatted value. However, I think grouping by the 2 single values and then concat on the client end will have the same effect.

Thanks for the help guys.
 
To clarify, if SQL Server (since it looks like T-Sql), you shouldn't need, but might need, parentheses, as in:
Code:
SELECT [b][COLOR=red]([/color][/b]VAL1 + ISNULL(VAL2, '')[b][COLOR=red])[/color][/b] AS ALIAS FROM TABLE1
 
Additionally, SQL Server's not real efficient at concatting strings, so you may want to leave it for your ASP code just based on that fact.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top