Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
<% oRS.MoveNext Wend

Unlike VB, SQL Server doesn't recognize the ampersand (&) as a valid concatenation operator. It's actually a bitwise AND for integer or binary datatypes. Use the plus sign (+) instead. For example, this query in the Pubs database fails with the error message you mentioned:

SELECT au_lname & au_fname AS Name 
FROM authors

But this statement works:

SELECT au_lname + au_fname AS Name 
FROM authors
DevX Pro
Language: SQL Server
Expertise: Beginner
Jun 5, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Concatening Columns Using AS

I'm trying to retrieve the "firstname" and "lastname" fields from a SQL Server database, place them into a column called "fullname" using the AS statement. When I simply retrieve "lastname," it works just fine. As soon as I do the concatenation, I get an error message from the SQL server with regard to the datatypes (mismatch of boolean and char). I've checked the datatypes of all fields in the SQL server and they are all char.

Here is my code:

Set oRS = oConn.Execute("SELECT FirstName &
' ' & LastName AS FullName, E_Mail, SchoolId from
Member2 where SchoolId='" & strSchoolId & "'") While Not oRs.EOF %>
<%=oRS("FullName")%> <%=oRS("E_Mail")%> <%=oRS("SchoolId")%>
Submit a Tip Browse "Database Development" Tips Browse All Tips
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date