SQL - As [Text()] Syntax?

I'm working on a project using SQL Report Builder 3.0 and using Stored Procedures. The following address displays having line-breaks as it should. I don't notice any difference including 'as [text()]' or not.

Okay, what does 'as [text()] do?

SELECT companyName + char(10) + address1 + char(10) + address2 as [text()]
FROM Addresses
For XML PATH(''), elements),1,200) as [Mailing_Address]
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Olaf DoschkeConnect With a Mentor Software DeveloperCommented:
It names the result column. No more, no less.

Bye, Olaf.
WorknHardrAuthor Commented:
Can you explain more...
Brian CroweConnect With a Mentor Database AdministratorCommented:
It creates an alias for the column.  In this case your column will be called "text()".  The brackets around it are delimiters that allow you to include characters that would otherwise cause a syntax error like a space or parentheses.
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

WorknHardrAuthor Commented:
I thought it had something to do with SQL Report Builder 3.0... Just a guess...
SharathConnect With a Mentor Data EngineerCommented:
It is just a column alias. You can execute the query in SSMS and observe the column alias as text().
WorknHardrAuthor Commented:
Cool, thx...
Olaf DoschkeSoftware DeveloperCommented:
Naming/Aliasing a column that way may be part of trickery with coe evaluating something, but on the SQL level it simply gives the column name for the expression companyName + char(10) + address1 + char(10) + address2. Without it, the field would be named expr_1, for example, or whatever automatic name would be given.

It's not even specifying the field type TEXT, tha would need a CONVERT or CAST.

Bye, Olaf.
All Courses

From novice to tech pro — start learning today.