October 8, 2023 at 10:13 am
Hi All,
Looking for following results. Can you please help in this.
Original
1 A US
Expected result
1,'A','US'
create table #tbl_Test (ID int, Name varchar(20),City varchar(20))
insert into #tbl_Test values (1,'A','US')
Select * from #tbl_Test
Expected result
1,'A','US'
October 8, 2023 at 11:23 am
SELECT ID
,Name = CONCAT ('''', Name, '''')
,City = CONCAT ('''', City, '''')
FROM #tbl_Test;
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 8, 2023 at 11:47 am
SELECT ID
,Name = CONCAT ('''', Name, '''')
,City = CONCAT ('''', City, '''')
FROM #tbl_Test;
Or even simpler if you have a lot of tables to do it for:
DECLARE @Quote varchar(100) = ''''
SELECT ID
,Name = CONCAT (@Quote, Name, @Quote)
,City = CONCAT (@Quote, City, @Quote)
FROM #tbl_Test;
October 8, 2023 at 12:00 pm
Do you want a single-cell result, rather than multiple columns?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
October 8, 2023 at 12:05 pm
I just need first line or row from the table. That I am going to copy and put it in insert statement to insert to table.
October 8, 2023 at 12:16 pm
If you look at this post there is a stored procedure that will generate the inserts for any table: https://www.sqlservercentral.com/forums/topic/generate-script-for-table-contents#post-4184688
Just install it and call it:
EXEC INFGenerateInserts @table_name='#tbl_Test';
October 8, 2023 at 12:29 pm
Thank you Jonathan AC Roberts.
It is working amazing.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply