-
MSSQL - Insert Statement with Print?
Can you insert plain text + data from one table into another?
Example:
Insert Into table2
Select
'My Data1 '+ ColumnX + 'My Data2, My Data3 ' as Line1,
'My Data' as Line2
From table1
'My Data*' is just print to be prepended and appened.
-
Yes.
create table table1 (columnx varchar(100))
create table table2 (Line1 varchar(100), Line2 varchar(100))
insert into table1 select 'a'
insert into table1 select 'b'
insert into table1 select 'c'
insert into table1 select 'd'
insert into table1 select 'e'
Insert Into table2(Line1,Line2)
Select'My Data1 '+ ColumnX + 'My Data2, My Data3 ' as Line1, 'My Data' as Line2
From table1
select * from table2
--results
My Data1 aMy Data2, My Data3 My Data
My Data1 bMy Data2, My Data3 My Data
My Data1 cMy Data2, My Data3 My Data
My Data1 dMy Data2, My Data3 My Data
My Data1 eMy Data2, My Data3 My Data
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|