Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Generate sql statement from select

Author  Topic 

zzaaqq1112003
Starting Member

4 Posts

Posted - 2003-02-27 : 02:29:56
Hi,
A newbie question:

how can I generate or append/insert text to the result of a select, I can do something like this from oracle:

select 'append this text '||number||';' from abc

This queries does not care what data type of 'name' is and it will output: append this text 123456;

can I do something like this with a simple select, I dont want to use precedure or function.
Ta



joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2003-02-27 : 07:17:22
Yes you can.

Select 'My Name is ' + namecolumn + '.'
From Table

You will however have to cast any columns that are nor character type columns. For instance, an int column would look something like:

Select 'The Number of records returned is ' + cast(count(*) as varchar(20))
From Table

Jeremy



Edited by - joldham on 02/27/2003 07:18:08
Go to Top of Page

zzaaqq1112003
Starting Member

4 Posts

Posted - 2003-02-27 : 07:46:26
thanks for this, I think I can also do ltrim(columname).

Either way (cast or ltrim), is a bit more complicated than what I use to :)


Go to Top of Page
   

- Advertisement -