日期:2014-05-17  浏览次数:20521 次

求助:SQL插入数据时加上‘’号
现有数据 01 02 03 。。。。
需要插入另一数据库中为 ‘01’,‘02’,'03' .... 需哟如何处理
或是插入后批量能更新也可,谢谢

------解决方案--------------------
SQL code
insert into tb(col) select '''01'''

------解决方案--------------------
SQL code

select '''name1'''--1
select ''name1''  --2
select 'name1'    --3

------解决方案--------------------
SQL code
-- 更新
update tb set col1= ''''+ col1 + '''';

------解决方案--------------------
insert table B(field) select '''' + fieldname + '''' from table A
------解决方案--------------------
4楼的 应该满足你的要求


------解决方案--------------------
仅供参考:
SQL code

CREATE TABLE t1
(
    id VARCHAR(5)
)
DECLARE @str VARCHAR(2000)='01 02 03'
SET @str=REPLACE(@str,' ',''''''' union all select ''''''')
SET @str='insert into t1 select '''''''+@str+''''''''
PRINT @str
EXEC (@str)
SELECT * FROM t1

---------------
id
'01'
'02'
'03'