April 4, 2005 at 6:52 am
I am using SQL Query Analyzer to run some select statements and print the results to file. I was wondering if there was a way to insert text into the results of the select statement.
I know in Oracle you could do it something like:
Select ||Our only member so far is || (firstname, lastname) ||. Let's all say hello.||from names
The results of the select statement would then look like:
Our only member so far is John Doe. Let's all say hello.
I think the "||" was called a break operator. Does anyone know if SQL Server has something similar?
Thanks
April 4, 2005 at 7:22 am
You could always do something like this :
Select 'This is a tables "' + name + '" / id = ' + cast(id as varchar(10)) from dbo.SysObjects where XType = 'U' order by Name
April 4, 2005 at 7:24 am
Select 'Our only member so far is ' + firstname + ', ' + lastname + '. Let''s all say hello.'
from names
Fix the formatting as you want.
April 4, 2005 at 7:54 am
Thanks for your replies. I am having trouble getting it to work. Maybe becuase I am using brackets and the distinct clause. For example:
Select distinct [first name] from names where [first name] is not null
So I tried:
select 'Welcome to our member ' distinct +[first name]+ '. Everyone say hello.' from names where [first name] is not null
and got Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax
I guess I don't understand what the "+" operator does.
April 4, 2005 at 8:11 am
select Distinct 'Welcome to our member ' +[first name]+ '. Everyone say hello.' from names where [first name] is not null
April 4, 2005 at 8:25 am
Hey that did it. Thanks!
April 4, 2005 at 8:37 am
The + operator simply concatenates the string literal(s) with the varchar (or similar string data type) data from the column firstname.
April 4, 2005 at 8:54 am
Thanks a lot. This will save me hours of work.
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply