declare @tb table(id int,name varchar(20)) declare @id int,@name varchar(20) select @id=1,@name ='aa' insert into @tb(id,name) values(@id,@name) select * from @tb
create table tb( id int,name varchar(20)) declare @id int,@name varchar(20),@sql varchar(100) select @id=1,@name ='aa' set @sql='insert into tb(id,name) values('''+cast(@id as varchar(20))+''','''+@name+''')' exec (@sql) select * from tb 2种方法
pCmd->CommandText=_bstr_t(L"INSERT INTO tmp(id,a,b,c) " L"VALUES("+id+","+a+","+b+","+c+")");
insert into tb values(.....)
--更新text字段的值 create table PE_Soft(SoftIntro text,ChannelID integer) insert into PE_Soft select 'aaa ',1004 union all select 'bbb ',1003 union all select 'ccc ',1002 declare @ptr binary(16) select @ptr=textptr(SoftIntro) from PE_Soft where ChannelID=1002 updatetext PE_Soft.SoftIntro @ptr null 0 'testing ' select * from PE_Soft drop table PE_Soft
参数化,好像要用到_ParameterPtr, 可以防止字符串中出现单引号时出问题
declare @tb table(id int,name varchar(20)) declare @id int,@name varchar(20) select @id=1,@name ='aa' insert into @tb(id,name) values(@id,@name) select * from @tb
declare @tb table(id int,name varchar(20))
declare @id int,@name varchar(20)
select @id=1,@name ='aa'
insert into @tb(id,name) values(@id,@name)
select * from @tb
declare @id int,@name varchar(20),@sql varchar(100)
select @id=1,@name ='aa'
set @sql='insert into tb(id,name) values('''+cast(@id as varchar(20))+''','''+@name+''')'
exec (@sql)
select * from tb
2种方法
L"VALUES("+id+","+a+","+b+","+c+")");
create table PE_Soft(SoftIntro text,ChannelID integer)
insert into PE_Soft
select 'aaa ',1004
union all
select 'bbb ',1003
union all
select 'ccc ',1002 declare @ptr binary(16)
select @ptr=textptr(SoftIntro) from PE_Soft where ChannelID=1002
updatetext PE_Soft.SoftIntro @ptr null 0 'testing '
select * from PE_Soft drop table PE_Soft
可以防止字符串中出现单引号时出问题
declare @id int,@name varchar(20)
select @id=1,@name ='aa'
insert into @tb(id,name) values(@id,@name)
select * from @tb