Solved

SQL - As [Text()] Syntax?

Posted on 2014-02-21
7
177 Views
Last Modified: 2014-02-24
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?

SUBSTRING
((
SELECT companyName + char(10) + address1 + char(10) + address2 as [text()]
FROM Addresses
For XML PATH(''), elements),1,200) as [Mailing_Address]
0
Comment
Question by:WorknHardr
7 Comments
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 117 total points
Comment Utility
It names the result column. No more, no less.

Bye, Olaf.
0
 

Author Comment

by:WorknHardr
Comment Utility
Can you explain more...
0
 
LVL 34

Assisted Solution

by:Brian Crowe
Brian Crowe earned 117 total points
Comment Utility
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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:WorknHardr
Comment Utility
I thought it had something to do with SQL Report Builder 3.0... Just a guess...
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 116 total points
Comment Utility
It is just a column alias. You can execute the query in SSMS and observe the column alias as text().
0
 

Author Closing Comment

by:WorknHardr
Comment Utility
Cool, thx...
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
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.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now